弹性搜索 - 使用查询UI搜索完全匹配的字符串 [英] Elastic search- search exact matching string using query UI

查看:556
本文介绍了弹性搜索 - 使用查询UI搜索完全匹配的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  {
id:100,
name :xxx,
嗜好:[板球,足球,唱歌和跳舞]

}

我需要从其他过滤唱歌和跳舞字符串。

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

I

 type:illegal_argument_exception,
reason:request [employee / data / _search]包含无法识别的参数:[Singing \}}}]


解决方案

您试图在URI中发送DSL查询,两者不会混合,请参见: https://www.elastic.co/guide/en/ elasticsearch / reference / 6.2 / search-search.html


搜索API允许您执行搜索查询并返回搜索匹配查询的匹配查询可以使用简单的查询字符串作为参数或我们提供您可以使用DSL并将其发送到您的请求正文中,或者将您的URL更改为

只是包含您想要使用的业余爱好query_string。像这样:

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

query_string部分也是URL编码的。我还为搜索值添加了引号,否则它们会将它们组合在一起。未编码版本:

 爱好:\Singing& dancing \


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?

解决方案

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\"

这篇关于弹性搜索 - 使用查询UI搜索完全匹配的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆