11

您使用什么 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 的示例,以及请求正文中的内容(如果可能),以便我了解。

4

4 回答 4

16

你可以试试:

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

或者

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

是你要找的吗?

于 2012-11-28T21:46:53.607 回答
7

如果你使用 sense 插件,你可以这样写

 POST myindex1/_search
{
"query": {"match_all": {}}
 }
于 2015-04-15T06:15:13.283 回答
6

你可以通过几种不同的方式来做到这一点。

1) 在字段上使用索引查询myindex1和在字段myindex2上使用术语查询。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"
      ]
    }
  }
}'

是的,您可以在这两个示例中的任何一个中将 terms 查询换成 match_all 查询(或此处的任何其他查询)。这是在第二个示例中执行 match_all 查询的方法:

curl -XPOST http://localhost:9200/myindex1,myindex2/_search -d '{
  "query": {
    "match_all": {}
  }
}'
于 2012-12-09T19:12:13.447 回答
1

我建议安装 elastic-head 插件。该界面上的第三个选项卡有一个查询生成器。您可以选择一个索引,构建一个查询,然后查看它生成的 dsl 查询。这是了解 dsl 查询语法的快速方法。

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

于 2013-08-24T00:22:01.343 回答