【发布时间】: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