正如文档中所解释的,当我使用 _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/