I have an Elasticsearch v2.4.2 index, I'm filling its .percolator type with a bunch of queries and some special values. query-docs looks like this:
"query" : {
"query_string" : {
"fields" : [ "title", "meta" ],
"query" : "notebooks AND clamps"
},
"key_id" : 14,
"owner_id" : 481,
"priority" : 50,
"special_id" : 477
}
I'm trying to delete some of these queries from .percolator, specifically those with even "key_id" values.
The problem is that I'm trying to perform a search on the .percolator but I'm not getting the results. for instance, I tried these curl calls:
curl 'localhost:9200/percolate_index_d/.percolator/_search?q=key_id:14&pretty'
curl 'localhost:9200/percolate_index_d/.percolator/_search?&pretty' -d '{ query:{filtered:{filter:{term:{"key_id":"14"}}}} }'
But I always get this:
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
I even tried using query.key_id
but no luck. Not sure if I'm doing something wrong, if it's possible to search on .percolator type or if there is some workaround for this.
Your above query is not correct at all. Try running it against your index and you'll see that you have syntax errors.
The correct syntax for your query is like this:
{
"query": {
"bool": {
"must": {
"query_string": {
"fields": [
"title",
"meta"
],
"query": "notebooks AND clamps"
}
},
"filter": [
{
"term": {
"key_id": 14
}
},
{
"term": {
"owner_id": 481
}
},
{
"term": {
"priority": 50
}
},
{
"term": {
"special_id": 477
}
}
]
}
}
}
Then you'll be able to search queries with key_id: 14
like this:
curl 'localhost:9200/percolate_index_d/.percolator/_search?q=query.bool.filter.term.key_id:14&pretty'
UPDATE
The metadata key_id|owner_id|priority|special_id fields of your query are not set in the right place, you need to set them outside of the query
field, like this_
{
"query" : {
"query_string" : {
"fields" : [ "title", "meta" ],
"query" : "notebooks AND clamps"
}
},
"key_id" : 14,
"owner_id" : 481,
"priority" : 50,
"special_id" : 477
}
After doing so, you'll be able to retrieve your queries with
curl 'localhost:9200/percolate_index_d/.percolator/_search?q=key_id:14&pretty'