【问题标题】:ElasticSearch returns 404 while multi-index, multi-type searchElasticSearch 在多索引、多类型搜索时返回 404
【发布时间】:2017-08-02 12:36:18
【问题描述】:

我们有一个要求,我们需要跨多个索引进行查询,如下所示
我们正在使用 ElasticSearch 5.1.1。
http://localhost:9200/index1,index2,index3/type1,type2/_search
查询:

{
 "query": {
  "multi_match": {
   "query": "data",
   "fields": ["status"]
  }
 }
}

但是我们可能事先不知道索引是否存在,如果上述任何一个索引都不存在,我们会得到以下错误。

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

一个明显的方法是检查索引是否已经存在,但我想避免额外的调用。
注意:至少 1 个索引将始终存在
是否可以避免此异常?
提前致谢 !!

【问题讨论】:

  • 为什么不改用index* 让ES解析具体的索引呢?
  • 感谢瓦尔的回复!但我认为这会降低搜索速度,因为我们有 300 多个具有相同模式的索引,即“索引”,而且我们不想将所有索引公开给消费者,我们只想公开他被授权的索引访问。
  • 你应该试试 ;-)

标签: elasticsearch


【解决方案1】:

"ignore_unavailable" 是解决这个问题的方法。将此作为搜索 url 中的查询参数传递。 例。 http://localhost:9200/index1,index2/type/_search?ignore_unavailable

即使任何一个索引都不存在,这也不会给出 404

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-28
    • 2022-06-18
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多