0

I'm mapping a couchbase gateway document and I'd like to tell elasticsearch to avoid indexing the internal attributes added by the gateway like the "_sync", this object contains another object named "channels" which has the following form:

"channels": {
  "i7de5558-32ad-48ca-bf91-858c3a1e4588": 12
}

So I guess the mapping of this object would be like:

"channels": {
     "type": "object",
     "properties": {
         "i7de5558-32ad-48ca-bf91-858c3a1e4588": {
             "type": "integer", 
             "index": "not_analyze"
         }
     }
}

The problem is that the keys are always changing, so I don't know if I should use a wildcard like this "*": {"type": "integer", "index": "not_analyze"} for this property or do something else. Any advice please?

2 Answers 2

1

If the fields are of integer types, you don't have to provide them explicitly in the mapping. You can create an empty mapping ,index documents with these fields. Elasticsearch will infer the type of field and update the mapping dynamically. You can also use dynamic templates for this.

{
 "mappings": {
  "my_type": {
     "dynamic_templates": [
        {
           "analysed_string_template": {
              "path_match": "channels.*",
              "mapping": {
                 "type": "integer"
              }
           }
        }
     ]
    }
   }
 } 
Sign up to request clarification or add additional context in comments.

Comments

0

There`s a dynamic way to do that as you need, is called dynamic template

Using templates you are able to create rules like this:

    PUT /my_index
{
    "mappings": {
        "my_type": {
            "date_detection": false
        }
    }
}

In your case you could create a template to set all news fields inside the channel object as not_analyzed. Hope it will help

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.