ElasticSearch datatype Keyword make it searchable

爷,独闯天下 提交于 2019-12-11 17:40:17

问题


I have data and and i want to create index and want it to make searchable and aggregatable both.If I use datatype keyword I can't search any string but can aggregate but if I use datatype text then I can't aggregate but can search any string. So please tell me how to resolve this problem. I am using elasticsearch 6


回答1:


The solution is to create a text field with a keyword sub-field so that you can do both, search text and aggregate values:

Your field mapping should look like this:

{
    "my_field": {
       "type": "text",
       "fields": {
           "keyword": {
               "type": "keyword"
           }
       }
    }
}

Using the above mapping, you can search on the my_field field and aggregate and my_field.keyword.



来源:https://stackoverflow.com/questions/51531760/elasticsearch-datatype-keyword-make-it-searchable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!