13Akaren
13Akaren

Reputation: 225

Elasticsearch dynamic template for all specific properties

my data structure is something like this:

{ field: xxx, 
  field2: xxx, 
  attrs: { 
     field3: xxx, 
     field4: xxx, 
     var: { field5: xxx, 
            field6: xxx
     } 
  }
}

I don't know attribute names in var, can I use dynamic mapping (and how) to make every attribute ONLY IN attrs.var.XXX searchable (set index: true)?

Upvotes: 0

Views: 240

Answers (1)

Joe - Check out my books
Joe - Check out my books

Reputation: 16925

You can use the following:

PUT unknown_paths
{
  "mappings": {
    "dynamic_templates": [
      {
        "stored_attrs_vars": {
          "path_match": "attrs.*.*",
          "mapping": {
            "index": true
          }
        }
      },
      {
        "no_index": {
          "path_match": "*",
          "unmatch": "attrs.*.*",
          "mapping": {
            "index": false
          }
        }
      }
      
    ]
  }
}

Note that if there's no actual field type, ES will still guess it for you. So even though you don't know the name of attrs.var, you'll probably know the types of field5 and 6, no?

Upvotes: 1

Related Questions