簡體   English   中英

如何在ElasticSearch中執行索引查詢?

[英]How to perform indices query in ElasticSearch?

您使用什么URL來執行索引查詢?

我在這里看到以下內容,但是這樣做的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的示例,如果可能的話,請求正文中包含的內容,以便我可以了解。

你可以嘗試:

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

要么

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

這是你在找什么?

如果你正在使用sense插件,你可以像這樣寫

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

你可以用幾種不同的方式做到這一點。

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查詢(或此處的任何其他查詢)的術語查詢。 以下是在第二個示例中執行match_all查詢的方法:

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

我建議安裝彈頭插件。 該接口上的第3個選項卡具有查詢構建器。 您可以選擇索引,構建查詢,並查看它生成的dsl查詢。 這是快速了解dsl查詢語法的一種方法。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM