ElasticSearch否定简单查询字符串中的短语和单词

nxagd54h  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(1)|浏览(454)

我尝试使用简单查询字符串否定ElasticSearch请求中的一些单词和短语。
我就是这么做的: &q=-"the witcher 3"-game-novel 所以基本上,试着否定一个短语和它后面的词。但这似乎行不通。如果我试着单独否定这些词,它就会起作用。如何在简单的查询字符串中否定短语和句子?

ymdaylpp

ymdaylpp1#

添加索引数据、搜索查询和搜索结果的工作示例。
索引数据:

{
    "name":"test"
}
{
    "name":"game"
}
{
    "name":"the witcher"
}
{
    "name":"the witcher 3"
}
{
    "name":"the"
}

搜索查询:

{
  "query": {
    "simple_query_string" : {
        "query": "-(game | novel) -(the witcher 3)",
        "fields": ["name"],
        "default_operator": "and"
    }
  }
}

搜索结果:

"hits": [
      {
        "_index": "stof_64133051",
        "_type": "_doc",
        "_id": "4",
        "_score": 2.0,
        "_source": {
          "name": "the"
        }
      },
      {
        "_index": "stof_64133051",
        "_type": "_doc",
        "_id": "3",
        "_score": 2.0,
        "_source": {
          "name": "the witcher"
        }
      },
      {
        "_index": "stof_64133051",
        "_type": "_doc",
        "_id": "1",
        "_score": 2.0,
        "_source": {
          "name": "test"
        }
      }
    ]

相关问题