Elastic search- search exact matching string using query UI

戏子无情 提交于 2019-12-24 19:09:01

问题


Here is my JSON .

{
    "id":100,
    "name":"xxx",       
    "hobbies":["cricket","footbal","singing & dancing"]

}

I need to filter "singing & dancing" string from "others". Executed below query.

http://localhost:9200/employeed/data/_search?q={"query":{"query_string":{"query" : "hobbies:Singing & dancing"}}}   

I am getting below exception.

"type": "illegal_argument_exception",
  "reason": "request [employee/data/_search] contains unrecognized parameter: [ Singing\"}}}]"  

Any help?


回答1:


You're attempting to send a DSL query in a URI. The two don't mix, see here: https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-search.html

The search API allows you to execute a search query and get back search hits that match the query. The query can either be provided using a simple query string as a parameter, or using a request body.

You can either use the DSL and send it in your request body, or change your URL to just include the hobbies query_string you want to use. Like this:

http://localhost:9200/employeed/data/_search?q=hobbies%3A%5C%22Singing%20%26%20dancing%5C%22

The query_string portion is also URL encoded. I've also added quotes around your search value, otherwise it will OR them together. The unencoded version:

hobbies:\"Singing & dancing\"


来源:https://stackoverflow.com/questions/48926849/elastic-search-search-exact-matching-string-using-query-ui

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