Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including and excluding indexes in Elasticsearch query

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.

like image 455
ba0708 Avatar asked Jan 03 '16 16:01

ba0708


1 Answers

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!!

like image 175
ChintanShah25 Avatar answered Nov 15 '22 09:11

ChintanShah25