Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch query on a specific index

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

like image 497
Kapoue Avatar asked Dec 13 '13 10:12

Kapoue


People also ask

How do you query an Elasticsearch index?

You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API's query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query. This query matches documents with a user.id value of kimchy .

How do I select a specific field in Elasticsearch?

There are two recommended methods to retrieve selected fields from a search query: Use the fields option to extract the values of fields present in the index mapping. Use the _source option if you need to access the original data that was passed at index time.

How do I query multiple indices in Elasticsearch?

To search multiple data streams and indices, add them as comma-separated values in the search API's request path. The following request searches the my-index-000001 and my-index-000002 indices. You can also search multiple data streams and indices using an index pattern.

How do I get all Elasticsearch index data?

Elasticsearch will get significant slower if you just add some big number as size, one method to use to get all documents is using scan and scroll ids. The results from this would contain a _scroll_id which you have to query to get the next 100 chunk. This answer needs more updates. search_type=scan is now deprecated.


2 Answers

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' 
like image 121
radtek Avatar answered Oct 19 '22 22:10

radtek


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

GET index/type/_search {    "query": {         "bool": {             "must": [                 {                     "term": {                         ...                     }                 }             ]         }     } } 
like image 42
Christian Müller Avatar answered Oct 19 '22 22:10

Christian Müller