【问题标题】:Including and excluding indexes in Elasticsearch query在 Elasticsearch 查询中包含和排除索引
【发布时间】:2016-01-03 16:09:01
【问题描述】:

我有以下 Elasticsearch 查询。

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

假设我想从这个搜索查询中排除 index2documentation states the following

它还支持通配符,例如:test*,以及 “添加”(+)和“删除”(-),例如:+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。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

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

    这会起作用

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

    希望这会有所帮助!

    【讨论】:

    • 我绝对不敢相信我没有发现这一点。我确实注意到那里的空间,但没有考虑太多。嗯,那太尴尬了!感谢你的回答! :-)
    • 我也有类似的问题。减号不起作用。 "resource.id": "-profiles_2"我有这个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 2018-05-14
    • 2014-05-30
    相关资源
    最近更新 更多