I have the following Elasticsearch query.
GET /index1,index2/type1,type2/_search?q=programming
Let's say that I want to exclude index2
from this search query. The documentation states the following:
It also support wildcards, for example: test*, and the ability to "add" (+) and "remove" (-), for example: +test*,-test3.
As far as I understand, I should be able to do the following.
GET /+index1,-index2/type1,type2/_search?q=programming
However, I get the below error.
{
"error": {
"root_cause": [
{
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_or_alias",
"resource.id": " index1",
"index": " index1"
}
],
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_or_alias",
"resource.id": " index1",
"index": " index1"
},
"status": 404
}
If I remove the plus and minus signs, the query runs fine. If I add a wildcard, it seems to work, e.g. the below query.
GET /index1,-*index2/type1,type2/_search?q=programming
However, that's not really what I want.
Why is my query not working when I use plus and minus signs to include or exclude indexes as the documentation states? Am I misunderstanding something?
I am using Elasticsearch 2.1.
You need to encode the +
sign as it is considered space
in URL string. See there is space
in "resource.id": " index1",
This will work
GET /%2Bindex1,-index2/type1,type2/_search?q=programming
Hope this helps!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With