How to disable nested data type keyword in dynamic mapping

I am using Elasticsearch 5.2.2. I have a requirement that in my index, some fields will be defined and some field will be dynamic. But the dynamic mapping is creating a structure something like this:

"COLOR": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
}

I don't want nested keyword field in dynamic mapping. Is there a way to supress it?

1 Like

Define a template and force the behavior you want for text fields.

hi David,

Thank you for your reply. I tried using dynamic templates as shown below, but it doesn't seem to work:

PUT myindex
{
    "settings" : 
    {
        "analysis": 
        {
          "analyzer": 
          {
            "lowercasespaceanalyzer": 
            {
              "type": "custom",
              "tokenizer": "whitespace",
              "filter": ["lowercase"]
            }
          }
        }
    },
    "mappings" : {
        "mytype" : {
            "properties" : {
                "extraction_date"  : { "type" : "date",
                "format": "MM-dd-yyyy HH:mm:ss"},
		            "markdown_price" : { "type" : "double" },
		            "regular_price" : { "type" : "double" },
		            "final_price" : { "type" : "double" }
            },
            "dynamic_templates": [
            {
              "strings_as_keywords": {
                "match_mapping_type": "text",
                "mapping": {
                  "type" : "text", "analyzer" : "lowercasespaceanalyzer", "tokenizer": "whitespace", "search_analyzer":"whitespace", "filter": ["lowercase"]
                }
              }
            }
          ]
        }
    }
}

After this when i do get mapping, i am still getting dynamic fields with keyword as a nested element.

Can you give the result of GET _mapping?
Can you give the result of GET _template?

hi David,

thanks for the quick reply. I am getting below as a result of get mapping:

{
  "myindex": {
    "mappings": {
      "mytype": {
        "dynamic_templates": [],
        "properties": {
          "24 hour timer": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "BRAND": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "COLOR": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },

.....

i don't want a nested keyword field as it will create extra field in index which will not be good for performance.

You can see that GET _mapping does not give the same result as your PUT myindex.

Did you really run the PUT request ? What is the result ?

David i ran the put mapping which only generates mapping for the 4 fields. Rest all are dynamic fields which i am sending via java api. It has close to 1200 columns. After putting the data, i am seeing dynamic mapping fields like 'BRAND', 'COLOR' etc. which are stored as 'text' type but also have 'keyword' type as a nested structure. I dont want that, i only need 'text' type using dynamic template.

it seems to be working using below code. I removed analyser and tokeniser from dynamic template:

PUT myindex
{
    "settings" : 
    {
        "index.mapping.total_fields.limit": 2000
    },
    "mappings" : {
        "mytype" : {
            "properties" : {
                "extraction_date"  : { "type" : "date",
                "format": "MM-dd-yyyy HH:mm:ss"},
		            "markdown_price" : { "type" : "double" },
		            "regular_price" : { "type" : "double" },
		            "final_price" : { "type" : "double" }
            },
            "dynamic_templates": [
            {
              "strings_as_text": {
                "match_mapping_type": "string",
                "mapping": {
                  "type": "text"
                }
              }
            }
            ]
        }
    }
}
1 Like

Ok great.

Please format your code using </> icon as explained in this guide. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.