curl - 在Elasticsearch Percolate API中过滤执行的查询

标签 curl elasticsearch

我有这个代码:

#!/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":[]}

我究竟做错了什么?

最佳答案

这行不通,因为您在为渗滤器建立索引后要求_percolate太早。

如果在渗滤之前在refresh索引上添加_percolator,它将起作用:
curl -XPOST 'http://localhost:9200/_percolator/_refresh'

关于curl - 在Elasticsearch Percolate API中过滤执行的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20224962/

相关文章:

php - Linux cURL 与 PHP cURL - POST 请求

curl - 将 wget cron 命令转换为 curl

php - 使用 CURL 将 JSON 数据发布到 API

ruby-on-rails - 耐嚼RSpec测试-预期索引 `client#person_client`将被更新,但是没有更新

elasticsearch - 复杂 Elasticsearch 查询

elasticsearch - Kibana中的脚本字段:添加值

python - GET curl 调用不返回 JSON 对象

jquery - 尽管可以使用 CURL 进行 POST,但使用 CORS 到 API 网关的 AJAX POST 不起作用

elasticsearch重新索引文档减少可用空间

php - 过滤查询 : Not null in elastic search