Elasticsearch query on a specific index

Kapoue picture Kapoue · Dec 13, 2013 · Viewed 39.7k times · Source

I have already searching this since 2 days now. I use the sense chrome plugin to be able to test my queries but I don't find how to specify on which index he is supposed to search. So my queries search on all the indexes and it isn't easy to use.

I have try the following syntaxes:

GET _search
{
    "query": {
        "term": {
           "_index": {
              "value": "dev_events2"
           }
        }
    }

}

GET _search
{
    "_index": "dev_events2",
    "query": {
        "match_all" : {  }
    }

}

GET _search
{
    "index": "dev_events2",
    "query": {
        "match_all" : {  }
    }

}

Regards,

Benjamin V.


Edit I finally have found the answer: just add the index name into the url for the get: localhost:9201/myIndexName

Answer

radtek picture radtek · Jan 9, 2017

Heres curl example what works, and allows you to search multiple indexes:

curl 'http://localhost:9200/myindex1,myindex2/_search?q=*'

For single specific index:

curl 'http://localhost:9200/myindex1/_search?q=*'

To find find index names:

curl 'localhost:9200/_cat/indices'

And if you want to search all indexes:

curl 'localhost:9200/_search?pretty'