Reputation: 41
Im pretty new to Elasticsearch. I have a requirement of creating ALL string fields with an "analyzed" and "not_analyzed" index. I have been able to do it for 1 or 2 fields, but how can I do this if I have 50 fields in my document? I have used the following code to create such an index on a few fields:
mapping = {
"my_type": {
"properties": {
"random_num": {"type": "string"},
"category": { "type":"multi_field", "fields":{ "category":{ "type":"string", "index":"analyzed" },"untouched":{ "type":"string", "index":"not_analyzed" } } },
"url": {"type": "string"},
"id": {"type": "string"},
"desc": { "type":"multi_field", "fields":{ "desc":{ "type":"string", "index":"analyzed" },"untouched":{ "type":"string", "index":"not_analyzed" } } }
}
}
}
I would really appreciate it if some one could help me out with this. Thanks!
Upvotes: 1
Views: 1893
Reputation: 19253
You can go through the document here. Using dynamic index templates , you can add rules like below and achienve the same. In the following example , I have enabled an additional field called raw ONLY if the size is less than 256 which would be not_analyzed.
{
"mappings": {
"my_type": {
"dynamic_templates": [
{
"string_fields": {
"mapping": {
"type": "string",
"fields": {
"raw": {
"index": "not_analyzed",
"ignore_above": 256,
"type": "string"
}
}
},
"match_mapping_type": "string",
"match": "*"
}
}
]
}
}
}
Upvotes: 1