【问题标题】:Filtering executed queries in the Elasticsearch Percolate API在 Elasticsearch Percolate API 中过滤执行的查询
【发布时间】:2013-11-27 18:40:12
【问题描述】:

我有这个代码:

#!/bin/bash

# Deletes, then creates the collection "foo".
curl -s -XDELETE localhost:9200/foo > /dev/null
curl -s -XPUT localhost:9200/foo > /dev/null

# Creates two percolators called "barbaz1" and "barbaz2" with different
# values in the "plugh" field.
curl -XPUT localhost:9200/_percolator/foo/barbaz1 -d '{
    "plugh": "xyzzy",
    "query": {
        "term": {
            "bar": "baz"
        }
    }
}'
echo ""

curl -XPUT localhost:9200/_percolator/foo/barbaz2 -d '{
    "plugh": "waldo",
    "query": {
        "term": {
            "bar": "baz"
        }
    }
}'
echo ""

# First filters out all queries whose "plugh" field is not "waldo", then
# tries to match those. Does NOT work as expected!
curl -XGET localhost:9200/foo/qux/_percolate -d '{
    "doc": {
        "bar": "baz"
    },
    "query": {
        "term": {
            "plugh": "waldo"
        }
    }
}'
echo ""

# Deletes the created percolators.
curl -s -XDELETE localhost:9200/_percolator/foo/barbaz1 > /dev/null
curl -s -XDELETE localhost:9200/_percolator/foo/barbaz2 > /dev/null

这将创建两个名为 barbaz1barbaz2 的过滤器,然后针对它们运行一个文档。我期望看到的是只有 barbaz2 匹配,而我得到的是:

{"ok":true,"_index":"_percolator","_type":"foo","_id":"barbaz1","_version":1}
{"ok":true,"_index":"_percolator","_type":"foo","_id":"barbaz2","_version":1}
{"ok":true,"matches":[]}

我做错了什么?

【问题讨论】:

    标签: curl elasticsearch


    【解决方案1】:

    这不起作用,因为您在为过滤器编制索引后过早询问 _percolate

    如果您在渗透之前在_percolator 索引上添加refresh,它将起作用:

    curl -XPOST 'http://localhost:9200/_percolator/_refresh'

    【讨论】:

    • 对,这似乎是问题所在。当只运行所有查询时,渗滤器是实时的,但它只是(接近)实时的,因为过滤查询意味着一个查询,它需要刷新以使数据可用于搜索。
    • 我可以确认此功能现在对我有用。谢谢!
    猜你喜欢
    • 2019-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    相关资源
    最近更新 更多