2013-12-13 27 views
13

L'ho già cercato da 2 giorni. Io uso il plugin sense chrome per poter testare le mie query ma non trovo come specificare su quale indice deve cercare. Quindi le mie ricerche effettuano ricerche su tutti gli indici e non sono facili da usare.Query Elasticsearch su un indice specifico

devo provare sintassi seguenti:

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

} 

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

} 

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

} 

saluti,

Benjamin V.


Edit ho finalmente trovato la risposta: basta aggiungere il nome di indice nell'URL per ottenere: localhost: 9201/myIndexName

+0

è anche possibile filtrare per _index: "" se la mappatura dei tuoi documenti ha "_index ": {" abilitato ": vero} – mconlin

+0

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

risposta

13

È inoltre possibile aggiungere l'indice/tipo al GET/PUT/DELETE ... La ricerca:

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

Heres ricciolo ad esempio ciò che funziona, e ti permette di cercare più indici:

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

per la singola indice specifico:

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

Per trovare i nomi degli indici di ricerca:

curl 'localhost:9200/_cat/indices' 

E se si desidera cercare tutti gli indici:

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

o specificare il tipo di indice

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