在Elasticsearch查询中包含和排除索引



我有以下Elasticsearch查询。

GET /index1,index2/type1,type2/_search?q=programming

假设我想从这个搜索查询中排除index2。文件说明如下:

它还支持通配符,例如:test*,以及"add"(+)和"remove"(-),例如:+test*、-test3。

据我所知,我应该能够做到以下几点。

GET /+index1,-index2/type1,type2/_search?q=programming

然而,我得到了以下错误。

{
  "error": {
    "root_cause": [
      {
        "type": "index_not_found_exception",
        "reason": "no such index",
        "resource.type": "index_or_alias",
        "resource.id": " index1",
        "index": " index1"
      }
    ],
    "type": "index_not_found_exception",
    "reason": "no such index",
    "resource.type": "index_or_alias",
    "resource.id": " index1",
    "index": " index1"
  },
  "status": 404
}

如果我去掉加号和减号,查询运行良好。如果我添加一个通配符,它似乎可以工作,例如下面的查询。

GET /index1,-*index2/type1,type2/_search?q=programming

然而,这并不是我真正想要的。

当我使用加号和减号在文档中包含或排除索引时,为什么我的查询不起作用?我是不是误解了什么?

我使用的是Elasticsearch 2.1。

您需要编码+符号,因为它在URL字符串中被视为space。参见"resource.id": " index1", 中有space

这将工作

GET /%2Bindex1,-index2/type1,type2/_search?q=programming

希望这能有所帮助!!

最新更新