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

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

es库的全文检索字段怎么搜索一个不分开的词组?

全文搜索的字段,如果想要查询一个用空格分开的词组,
例如:‘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)"
}
这两条查询不出来。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

可以用这个,match查询。

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...