0

I'm wondering if there is a way to set all nested field to a specific type

The main reason I'm looking for something like that is because the attributes inside category are not not known and can vary.

That's the mapping I have, and every single property must have its type explicitly set:

PUT data
{
  "mappings": {
    "properties": {      
      "category": {
        "type": "nested",
        "properties": {
          "mode": {
            "type":   "text",
            "analyzer": "keyword"
          },
          "sequence": {
            "type":   "text",
            "analyzer": "keyword"
          }
        }
      }
    }
  }
}

I'm looking for something like this pseudo mapping below:

PUT data
{
  "mappings": {
    "properties": {      
      "category": {
        "type": "nested",
        "properties.*": {
            "type":   "text",
            "analyzer": "keyword"              
        }
      }
    }
  }
}

Maybe this is not the way to go and if you have any other solution to handle these dynamic attributes, it will be really appreciated.

1 Answer 1

1

You can achieve this with dynamic templates

PUT data
{
  "mappings": {
    "dynamic_templates": [
      {
        "category_fields": {
          "path_match":   "category.*",
          "mapping": {
            "type":   "text",
            "analyzer": "keyword"              
          }
        }
      }
    ]
  },
  "properties": {
    "category": {
      "type": "nested"
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.