不要急,总有办法的

multi_match中query词的问题

Elasticsearch | 作者 hy690322863 | 发布于2020年10月29日 | 阅读数:1625

"query": {
"bool": {
"must": {
"multi_match": {
"query": "red hat cat"
}
}
}
我希望搜索的时候"red hat"必须挨在一起为一个词组,"cat"可以分开
要怎么做?
求各位大神指导
已邀请:

pony_maggie - 公众号:犀牛饲养员的技术笔记

赞同来自: hy690322863

GET test_index/_search
{
  "query": {
    "bool": {
      "should": [
        {"match_phrase": {
          "title": "red hat"
        }},
        {"match": {
          "title": "cat"
        }}
      ]
    }
  }
}

BKing - Double non. Open source software and dreamer (English Français Japanese Korean ) learners

赞同来自: hy690322863

(⊙o⊙)…    "multi_match" 用来进行多字段匹配的,如果你要对于同一个字段的内容进行匹配,可以选择match进行操作。
DELETE index_test

POST index_test/_bulk
{"index":{"_id":1}}
{"cont":"red hat is excellent software."}
{"index":{"_id":2}}
{"cont":"red looks like hat."}
{"index":{"_id":3}}
{"cont":"red and hat are uesd in the cat."}
{"index":{"_id":4}}
{"cont":"The cat has the red hat."}
{"index":{"_id":5}}
{"cont":"The red hat belongs to the cat."}
{"index":{"_id":6}}
{"cont":"The cat wears a hat."}

#red hat 和 cat 可以不在同一个内容中
GET index_test/_search
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"cont": "red hat"
}
}
],
"should": [
{
"match": {
"cont": "cat"
}
}
]
}
}
}

#red hat 和 cat 一定要在同一内容中
GET index_test/_search
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"cont": "red hat"
}
},
{
"match": {
"cont": "cat"
}
}
]
}
}
}

希望以上内容对你有所帮助。

要回复问题请先登录注册