types - 限制 Percolator 调用 ElasticSearch 中的类型

标签 types elasticsearch restrict

正如文档中所解释的,当我使用 _percolator 存储查询时,例如:

curl -XPUT localhost:9200/_percolator/test/kuku -d '{
  "color" : "blue",
  "query" : {
      "term" : {
        "field1" : "value1"
      }
   }
}'

当我在“test”索引上过滤文档时,将运行此查询,但如果我想将其限制为“test”索引的“foo”类型,唯一的解决方案是在查询中添加一个类型:

curl -XPUT localhost:9200/_percolator/test/kuku -d '{
   "type":"foo",
   "color" : "blue",
   "query" : {
       "term" : {
         "field1" : "value1"
       }
  }
}'

添加文档时使用

curl -XGET localhost:9200/test/type1/_percolate -d '{
   "doc" : {
      "field1" : "value1"
    },
    "query" : {
      "term" : {
         "type" : "foo"
      }
    } 
  }'

还有其他解决办法吗? 我试过了

curl -XPUT localhost:9200/_percolator/test/foo/kuku

但是它不起作用。

最佳答案

另一种方法是将原始查询包装到过滤查询中,并为 _type 添加术语过滤器:

{
    "query": {
        "filtered":{
            "query": {
                "term":{
                    field1" : "value1"
                }
             },
             "filter": {
                 "term": {
                     "_type" : "type1"
                 }
              }
          }
     }
}

关于types - 限制 Percolator 调用 ElasticSearch 中的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13050783/

相关文章:

c - 限制具有多个只读文字字符串的关键字

c - 如果某些限制指针指向同一个对象,为什么编译器不生成警告或错误?

elasticsearch - Allegro嵌入式ElasticSearch失败错误:指定的超时时间内群集未达到黄色状态

apache - 我如何使用 htaccess 限制 ip block -range-?

arrays - 为什么 Swift 有时会将混合类型数组视为单一类型数组?

java - 如何将 Hibernate String 列转换为 Enum?

elasticsearch - ElasticSearch嵌套查询按数组中的第二项过滤

json - Kibana - 如何导出搜索结果

c++ - 如何在 C++ 中使用模板?

Swift 类型下标