elasticsearch 在elastichsearch中搜索精确词

ecbunoof  于 2023-02-03  发布在  ElasticSearch
关注(0)|答案(1)|浏览(105)

使用elasticseach,我想用两个词搜索所有文档。
我使用:
{ "query": { "match": { "text": "word1 word2" } } }
但是,而不是有word1和word2的文档,我有word1或word2的文档。我怎么能搜索word1和word2的文档?

kzipqqlq

kzipqqlq1#

可以在查询中使用operator
operator参数可以设置为或或和来控制布尔子句(默认为或)。

POST test_index/_doc
{"text":"word1"}
POST test_index/_doc
{"text":"word2"}
POST test_index/_doc
{"text":"word1 word2"}

GET test_index/_search
{
  "query": {
    "match": {
      "text": {
        "query": "word1 word2",
        "operator": "and"
      }
    }
  }
}

参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#query-dsl-match-query-boolean

相关问题