elasticsearch - Elasticsearch 否定简单查询字符串中的短语和单词

标签 elasticsearch query-string

我正在尝试使用简单查询字符串否定Elastic Search请求中的某些单词和短语。
这是我的工作:&q=-"the witcher 3"-game-novel因此,基本上,试图否定短语和其后的单词。但这似乎不起作用。
如果我尝试单独否定单词,那么它会起作用。
如何取消简单查询字符串中的短语和句子?

最佳答案

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

{
    "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"
        }
      }
    ]

关于elasticsearch - Elasticsearch 否定简单查询字符串中的短语和单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64133051/

相关文章:

ruby-on-rails - 使用 Homebrew 软件安装了 elasticsearch,但找不到配置文件

java - Elasticsearch聚合查询

elasticsearch - 如何按日期限制 ElasticSearch API 计数?

使用不同的查询字符串转到同一页面的 HTML anchor 链接

java - 当相对 URI 包含空路径时,Java 的 URI.resolve 是否与 RFC 3986 不兼容?

elasticsearch - “矢量搜索”在 Elastic Search 版本 8.9.0 中不起作用

ElasticSearch 中的 Python 自定义脚本

apache - 将 CGI 参数传递给 Windows 上 Apache 中的可执行文件

php - 查询字符串的 Javascript 或 PHP 语法突出显示?

php - 在 WooCommerce 感谢页面上添加产品 ID 和订单号作为查询字符串