0
votes

I have the following mapping in elasticsearch:

{
  "doc": {
    "properties": {
      "fileContent": {
        "properties": {
          "dimension": {
            "properties": {
              "jurisdiction": {
                "type": "string"
              },
              "language": {
                "type": "string"
              },
              "region": {
                "type": "string"
              },
              "trueValue": {
                "type": "string"
              }
            }
          },
          "dynamicGeneratedProperty1": {},
          "dynamicGeneratedProperty2": {},
          "dynamicGeneratedPropertyN": {}
        }
      }
    }
  }
}

I'm trying to configure elasticsearch to index only the dimension property from the fileContent, but the other properties, that are generated dynamically, I don't want to be indexed.

I have tried the following config, but it doesn't seem to work properly:

curl -XPUT 0:9200/river1/doc/_mapping -d '
  {
    "doc": {
      "properties": {
        "fileContent": {
          "type": "object",
          "store": true,
          "enabled": false,
          "properties": {
            "dimension": {
              "type": "object",
              "store": true,
              "enabled": true
            }
          }
        }
      }
    }
  }
'

It applies the "enabled": false config from the parent property, that is fileContent, and it ignores the sub-property config, that tells to index the dimension.

I know that there is also some template config, on which you tell elastic to index properties based on a defined-template, in which you can specify some sort of regex: https://www.elastic.co/guide/en/elasticsearch/reference/0.90/indices-templates.html. But I don't know how to use it exactly.

I am using a quite old version of elasticsearch, 0.93.

1

1 Answers

0
votes

I have found the answer to this problem. The solution is to use the dynamic property set to false for the fileContent object. Here is the documentation for it: https://www.elastic.co/guide/en/elasticsearch/reference/0.90/mapping-dynamic-mapping.html

Therefore, the final config should look like this:

curl -XPUT 0:9200/river1/doc/_mapping -d '
    {
      "doc": {
        "properties": {
          "fileContent": {
            "type": "object",
            "dynamic": false,
            "properties": {
              "dimension": {
                "type": "object",
                "dynamic": true
              }
            }
          }
        }
      }
    }
'

This will not allow elasticsearch to index and add any other properties in the fileContent object, while the dimensions property can be populated dynamically, and indexed, as well.