0

我有一个 Elasticsearch v2.4.2 索引,我正在用一堆查询和一些特殊值填充它的 .percolator 类型。查询文档看起来像这样:

"query" : {
      "query_string" : {
        "fields" : [ "title", "meta" ],
        "query" : "notebooks AND clamps"
      },
      "key_id" : 14,
      "owner_id" : 481,
      "priority" : 50,
      "special_id" : 477
    }

我正在尝试从 .percolator 中删除其中一些查询,特别是那些甚至具有“key_id”值的查询。

问题是我正在尝试对 .percolator 执行搜索,但没有得到结果。例如,我尝试了这些 curl 调用:

curl 'localhost:9200/percolate_index_d/.percolator/_search?q=key_id:14&pretty'


curl 'localhost:9200/percolate_index_d/.percolator/_search?&pretty' -d '{ query:{filtered:{filter:{term:{"key_id":"14"}}}} }'

但我总是得到这个:

 {
      "took" : 6,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
      },
      "hits" : {
        "total" : 0,
        "max_score" : null,
        "hits" : [ ]
      }
    }

我什至尝试使用query.key_id但没有运气。不确定我是否做错了什么,是否可以搜索 .percolator 类型,或者是否有一些解决方法。

4

1 回答 1

1

您的上述查询根本不正确。尝试对你的索引运行它,你会发现你有语法错误。

您的查询的正确语法如下所示:

{
  "query": {
    "bool": {
      "must": {
        "query_string": {
          "fields": [
            "title",
            "meta"
          ],
          "query": "notebooks AND clamps"
        }
      },
      "filter": [
        {
          "term": {
            "key_id": 14
          }
        },
        {
          "term": {
            "owner_id": 481
          }
        },
        {
          "term": {
            "priority": 50
          }
        },
        {
          "term": {
            "special_id": 477
          }
        }
      ]
    }
  }
}

然后你就可以key_id: 14像这样搜索查询:

curl 'localhost:9200/percolate_index_d/.percolator/_search?q=query.bool.filter.term.key_id:14&pretty'

更新

您查询的元数据 key_id|owner_id|priority|special_id 字段未设置在正确的位置,您需要将它们设置在query字段之外,像这样_

{
  "query" : {
    "query_string" : {
      "fields" : [ "title", "meta" ],
      "query" : "notebooks AND clamps"
    }
  },
  "key_id" : 14,
  "owner_id" : 481,
  "priority" : 50,
  "special_id" : 477
} 

这样做后,您将能够检索您的查询

curl 'localhost:9200/percolate_index_d/.percolator/_search?q=key_id:14&pretty'
于 2016-11-26T05:22:02.127 回答