Elasticsearch query on a specific index

68.6k views Asked by At

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

3

There are 3 answers

0
radtek On

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'
1
Michael Wong On
GET index_name/_search
{
    "query": {
        "match_all" : { }
    }
}

or specify the index type

GET index_name/index_type/_search
{
    "query": {
        "match_all" : { }
    }
}
0
Christian Müller On

You can also add the index/type to the GET/PUT/DELETE ... query:

GET index/type/_search
{
   "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        ...
                    }
                }
            ]
        }
    }
}