使用groovy开关的Elasticsearch percolation +脚本过滤器

时间:2015-11-30 18:28:20

标签: elasticsearch groovy elasticsearch-percolate

我无法使用groovy开关使用脚本过滤器进行渗透。

我创建了一个像这样的文档

curl -XPUT http://localhost:9200/perc_test/perc_type/1 -d'{"v": true}'

=> (OK) {"_index":"perc_test","_type":"perc_type","_id":"1","_version":1,"created":true}

我检查此文档是否符合我的查询。请注意,在我的实际用例中,我需要使用一个开关,因此需要进行奇怪的脚本查询。

curl -XPOST http://localhost:9200/perc_test/_search -d'
{
  "query": {
    "filtered": {
      "query": {"match_all": {}},
      "filter": {
        "script": {
          "script": "switch (_source[\"v\"]) {\n case { it == true }:\n return true \n default: \n return false\n}"
        }
      }
    }
  }
}'

=> (OK) {"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"perc_test","_type":"perc_type","_id":"1","_score":1.0,"_source":{"v": true}}]}}

我向percolator api注册完全相同的查询。

curl -XPOST http://localhost:9200/perc_test/.percolator/1 -d'
{
  "query": {
    "filtered": {
      "query": {"match_all": {}},
      "filter": {
        "script": {
          "script": "switch (_source[\"v\"]) {\n case { it == true }:\n return true \n default: \n return false\n}"
        }
      }
    }
  }
}'

=> (OK){"_index":"perc_test","_type":".percolator","_id":"1","_version":1,"created":true}

然后我尝试渗透已注册的文档,但它不起作用

curl -XGET http://localhost:9200/perc_test/perc_type/1/_percolate

=> (KO) {"took":1,"_shards":{"total":1,"successful":1,"failed":0},"total":0,"matches":[]}%

相同的结果
curl -XPOST http://localhost:9200/perc_test/perc_type/_percolate -d'{"doc": {"v": true}}'

=> (KO) {"took":1,"_shards":{"total":1,"successful":1,"failed":0},"total":0,"matches":[]}%

0 个答案:

没有答案