Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

全文搜索的字段,如果想要查询一个用空格分开的词组,
例如:‘Gritty Hope’,使用什么样的es库查询语句,能达到查询出来的结果必须都包含这个词组,就是说,只包含‘Gritty’或‘Hope’的数据查询不出来。这两个单词都有的,也必须是‘Gritty Hope’这样的才能查询到。应该怎么写这个查询语句啊?

查询关键词:‘Gritty Hope’,
{
"id":'001',
"title": "Gritty Hope: now what could possibly go right?"
},
{
"id":'002',
"title": "gritty hope: now what could possibly go right?"
}
这两条可以查询出来,
{
"id":'002',
"title": "The Batman Trailer: Gritty, Haunting, & Fu*king Epic"
},
{
"id":'003',
"title": "Raymond James Keeps a Hold Rating on Hope Bancorp (HOPE)"
}
这两条查询不出来。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

可以用这个,match查询。

GET your_index/_search
{
  "query": {
    "match": {
      "title": {
        "query": "Gritty Hope",
        "operator": "AND"
      }
    }
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...