2

我正在尝试查找保存在 Percolator Index 中的特定查询。没有看到任何相关的文档。SOF问题之一有助于将所有查询保留在索引中。

我的一个示例查询保留在 Percolator 中

curl -XPUT "http://localhost:9200/notifications/.percolator/1" -d'
{
  "query" : {
      "match" : {
        "tags" : "elasticsearch"
      }}
}'

和其他示例查询,如

curl -XPUT "http://localhost:9200/notifications/.percolator/4" -d'
{
"query" : {
    "bool": {
        "should": [
           { "term": {
              "tags": "Hbase"
                }
           },
            {  "term": {
                 "user": "abc"
              }
           }
        ]
        , "minimum_number_should_match": 1
    }
}
}'

有什么方法可以提取特定查询吗?根据上面的例子,我想找到一个与用户匹配的查询:“abc”

4

2 回答 2

1

因此,对于您的示例,如果我们只是更新minimum_should_match为 2 而不是 1,我们将无法使用 percolator API

{
    "doc" : {
        "user" : "abc"
    }
}

获取您想要的查询。

这是一个想法:

根据Percolator Docs,存储在 percolator 索引中的查询的默认映射是:

{
    ".percolator" : {
        "properties" : {
            "query" : {
                "type" : "object",
                "enabled" : false
            }
        }
    }
}

您可能会使用适当的分析器使用新字段更新此映射,这将允许您以您想要的方式搜索查询,而无需提供文档来查找将返回文档的查询。假设这个新字段custom_query_rep可以包含查询的某种表示形式(类似于查询的 JSON.stringify(query) 版本),您在使用过滤器索引查询时指定这些表示形式。这将允许您使用以下查询查询渗透器索引:

{
    "query" : {
        "bool" : {
            "must" : [
                { "match" : { "custom_query_rep" : "user" } },
                { "match" : { "custom_query_rep" : "abc" } }
            ]
        }
    }
}

当然,这是一个非常简单的案例。该解决方案似乎有些有限,对于更复杂的查询需要更多的思考。

于 2015-11-04T18:58:40.970 回答
0

由于 Percolator 类型被定义为动态的,在将查询(即文档)添加到 Percolator 时,我们可以将字段添加到搜索上。基于此信息,示例查询 1 将变为

curl -XPUT "http://localhost:9200/notifications/.percolator/1" -d'
{
"query" : {
    "match" : {
        "tags" : "db"
    }
},
"tags" : "db"
}'

同样,示例查询 2 将是

curl -XPUT "http://localhost:9200/notifications/.percolator/4" -d'
{
"query" : {
"bool": {
    "should": [
       {"term": {"tags": "Hbase"}},
       {"term": {"user": "abc"}}
    ]
    , "minimum_number_should_match": 1
  }}
 "tags": "hbase"
 "user": "abc" 
 }'

最后,我们照常查询

curl -XPOST "http://localhost:9200/notifications/.percolator/_search" -d'
{
"query": {
  "term": {
     "user": "abc"
  }
}
}'

这个解决方案对我有用。可能有更好的解决方案。想听听专家的意见。

于 2015-11-04T19:58:26.680 回答