在Elasticsearch查询中包含和排除索引 [英] Including and excluding indexes in Elasticsearch query

查看:447
本文介绍了在Elasticsearch查询中包含和排除索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Elasticsearch查询。

I have the following Elasticsearch query.

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

假设我要从 index2 中排除此搜索查询。 文档指出以下内容

Let's say that I want to exclude index2 from this search query. The documentation states the following:


它还支持通配符,例如:test *,以及
的功能添加(+)和删除(-),例如:+ test *,-test3。

It also support wildcards, for example: test*, and the ability to "add" (+) and "remove" (-), for example: +test*,-test3.

据我所知,我应该能够请执行以下操作。

As far as I understand, I should be able to do the following.

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
}

如果删除加号和减号,则查询运行正常。如果我添加通配符,它​​似乎可以工作,例如

If I remove the plus and minus signs, the query runs fine. If I add a wildcard, it seems to work, e.g. the below query.

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

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

However, that's not really what I want.

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

Why is my query not working when I use plus and minus signs to include or exclude indexes as the documentation states? Am I misunderstanding something?

我正在使用Elasticsearch 2.1。

I am using Elasticsearch 2.1.

推荐答案

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

You need to encode the + sign as it is considered space in URL string. See there is space in "resource.id": " index1",

这将起作用

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

希望这会有所帮助!

这篇关于在Elasticsearch查询中包含和排除索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆