2013-12-13 59 views
13

我已經從2天內開始搜索。我使用sense chrome插件來測試我的查詢,但我沒有找到如何指定他應該搜索哪個索引。因此,我的查詢搜索所有索引,並且使用起來並不容易。Elasticsearch在特定索引上的查詢

我有嘗試以下語法:

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

} 

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

} 

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

} 

問候,

本傑明五


編輯我終於找到了答案:只需添加索引名到URL獲取:localhost:9201/myIndexName

+0

您還可以通過_index篩選:「」如果您的文檔映射具有「_index 「:{」enabled「:true} – mconlin

+0

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html –

回答

13

您還可以將索引/類型添加到GET/PUT/DELETE ...查詢:

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

繼承人捲曲例子是什麼在起作用,並允許你搜索多個索引:

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

對於單個具體指標:

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

尋找索引名稱:

curl 'localhost:9200/_cat/indices' 

如果你要搜索的所有索引:

curl 'localhost:9200/_search?pretty' 
1
GET index_name/_search 
{ 
    "query": { 
     "match_all" : { } 
    } 
} 

或指定索引類型

GET index_name/index_type/_search 
{ 
    "query": { 
     "match_all" : { } 
    } 
}