Elasticsearch: How to make all properties of object type as non analyzed? -


i need create elasticsearch mapping object field keys not known in advance. also, values can integers or strings. want values stored non analyzed fields if strings. tried following mapping:

put /my_index/_mapping/test {   "properties": {     "alert_text": {       "type": "object",       "index": "not_analyzed"     }   } } 

now index created fine. if insert values this:

post /my_index/test {   "alert_text": {     "1": "hello moto"   } } 

the value "hello moto" stored analyzed field using standard analyzer. want stored non analyzed field. possible if don't know in advance keys can present ?

try dynamic templates. feature can configure set of rules fields created dynamically.

in example i've configured rule think need, i.e, strings fields within alert_text not_analyzed:

put /my_index {     "mappings": {         "test": {             "properties": {                 "alert_text": {                   "type": "object"                    }             },             "dynamic_templates": [                 {                     "alert_text_strings": {                         "path_match": "alert_text.*",                          "match_mapping_type": "string",                         "mapping": {                             "type": "string",                             "index": "not_analyzed"                         }                     }                 }             ]         }     } }  post /my_index/test {   "alert_text": {     "1": "hello moto"   } } 

after executing requests above can execute query show current mapping:

get /my_index/_mapping 

and obtain:

{    "my_index": {       "mappings": {          "test": {             "dynamic_templates": [                {                   "alert_text_strings": {                      "mapping": {                         "index": "not_analyzed",                         "type": "string"                      },                      "match_mapping_type": "string",                      "path_match": "alert_text.*"                   }                }             ],             "properties": {                "alert_text": {                   "properties": {                      "1": {                         "type": "string",                         "index": "not_analyzed"                      }                   }                }             }          }       }    } } 

where can see alert_text.1 stored not_analyzed.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -