Home > OS >  Elasticsearch 'match' doesn't work with Dynamic Templates
Elasticsearch 'match' doesn't work with Dynamic Templates

Time:09-29

I am trying to create a dynamic template based on some matching criteria but when I am using "match" attribute it's not working. More specific , I want to create a dynamic template with the standard_analyzer (already imported in settings) when field ends with _analyze.

Desired results on Mapping:

{
       "count" : {
          "type" : "integer"
        },
        "is_top" : {
          "type" : "boolean"
        },
       "keywords_analyze":{
          "type":"text",
          "fields":{
             "std_analyzer":{
             "type":"text",
             "term_vector":"yes",
             "analyzer":"standard_analyzer"
         }
      }
   }
}

currently mapping i am doing:

  "mappings": {
    "dynamic_templates": [
      {
        "integers": {
          "match_mapping_type": "long",
          "mapping": {
            "type": "integer"
          }
        }
      },
        {
        "strings": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "text"
          }
        }
      },
      {
        "strings_analz": {
          "match": "*_analyze",
          "mapping": {
            "type": "text",
            "analyzer" : "standard_analyzer"
            "fields": {
                "keyword": {
                  "type":  "keyword",
                  "ignore_above": 256
                }
            }
          }
        }
      }
    ]
  }
}

with result:

  "count" : {
          "type" : "integer"
        },
        "is_top" : {
          "type" : "boolean"
        },
        "keywords_analyze" : {
          "type" : "text"
        },
        "count" : {
          "type" : "integer"
        }

CodePudding user response:

You just need to move the strings_analz template before the strings one, because the first one that matches is the one that is picked.

  • Related