2012-11-28 74 views
11

您使用什麼URL來執行索引查詢?如何在ElasticSearch中執行索引查詢?

我在這裏看到以下內容,但是也要做什麼URL? http://www.elasticsearch.org/guide/reference/query-dsl/indices-query.html

我知道如何在彈性搜索查詢的唯一方法是與URI:

http://localhost:9200/myindex 

我有是我有多個指標用不同的文件 myindex1 myindex2 myindex3

問題

我希望能夠對myindex1和myindex2(或者只是myindex2和myindex3)執行任何查詢。

這可能嗎?也可以你把索引查詢與QueryDSL像MATCH_ALL查詢或條款查詢:

http://www.elasticsearch.org/guide/reference/query-dsl/terms-query.html

請展示了一個URL的一個例子,什麼雲在請求的主體如果可能的話,所以我可以得到一個想法。

回答

7

如果您正在使用感插件,您可以這樣寫

POST myindex1/_search 
{ 
"query": {"match_all": {}} 
} 
16

你可以嘗試:

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

或者

curl -XPOST http://localhost:9200/myindex1,myindex2/_search -d '{ 
    // your query here 
}' 

是不是你在找什麼?

6

你可以通過幾種不同的方法來做到這一點。

1)使用myindex1myindex2上的索引查詢,並在title字段中使用條件查詢。

curl -XPOST http://localhost:9200/_search -d '{ 
    "query": { 
    "indices": { 
     "indices": [ 
     "myindex1", 
     "myindex2" 
     ], 
     "query": { 
     "terms": { 
      "title": [ 
      "foo", 
      "bar" 
      ] 
     } 
     } 
    } 
    } 
}' 

2)通過在URI中指定要搜索的索引(使用完全相同的術語查詢)。

curl -XPOST http://localhost:9200/myindex1,myindex2/_search -d '{ 
    "query": { 
    "terms": { 
     "title": [ 
     "cookies", 
     "cake" 
     ] 
    } 
    } 
}' 
在任的兩個例子

是的,你可以換出一個MATCH_ALL查詢條件查詢(或任何其他查詢here,真的)。在第二個示例中,您將如何執行match_all查詢:

curl -XPOST http://localhost:9200/myindex1,myindex2/_search -d '{ 
    "query": { 
    "match_all": {} 
    } 
}' 
+1

指數:查詢在ElasticSearch 5棄用 –

1

我建議安裝elastic-head插件。該界面上的第三個標籤有一個查詢生成器。您可以選擇索引,構建查詢,並查看它生成的dsl查詢。這是快速瞭解dsl查詢語法的快速方法。

http://mobz.github.io/elasticsearch-head/