1

When trying to add term facets, I face the issue that the terms get tokenized into separate words. For example, if an attribute (field) Kind has values medium kind of shirt and large kind of shirt, the terms become - medium, large, kind, of, shirt.

To fix this, it was suggested that I change the mapping to include "index": "not_analyzed" for each attribute field. The problem is that the mapping is generated dynamically, for example -:

"attributes": {
   "properties": {
      "kind": {
         "type": "string"
      },
      "color": {
         "type": "string"
      },
      "size": {
         "type": "string"
      }
   }
}

Simply setting the "not_analyzed" bit inside "attributes" will not do. Is there a way to set the index attribute for each sub-field inside the attributes field?

PritishC
  • 508
  • 8
  • 18
  • 1
    If it's generated dynamically, then you should be able to define a dynamic template for it where you can specify the `index` attribute. See this for details on dynamic mapping: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/custom-dynamic-mapping.html – Andrei Stefan Jan 14 '15 at 07:27

1 Answers1

1

Thanks to Andrei's comment, I was able to figure out how to apply the setting.

I added a dynamic_templates section to my mapping as follows -:

"dynamic_templates": [
    {
        "string_template": {
            "path_match": "attributes.*",
            "match_mapping_type": "string",
            "mapping": {
                "type": "string",
                "index": "not_analyzed"
            }
        }
    }
]

This does the trick, and now each sub-field with "string" type has their "index" setting as "not_analyzed". The terms are no longer tokenized.

PritishC
  • 508
  • 8
  • 18