我们有一个要求,我们需要跨多个索引进行查询,如下所示
我们正在使用 ElasticSearch 5.1.1。
http://localhost:9200/index1,index2,index3/type1,type2/_search
查询:
{
"query": {
"multi_match": {
"query": "data",
"fields": ["status"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
然而,我们可能事先不知道索引是否存在,如果上述索引不存在,我们会得到以下错误。
{
"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
}
Run Code Online (Sandbox Code Playgroud)
一种明显的方法是检查索引是否已经存在,但我想避免额外的调用。
注意:至少有 1 个索引始终存在
是否可以避免此异常?
提前致谢 !!
“ignore_unavailable”是解决方案。将此作为搜索 url 中的查询参数传递。埃克萨。http://localhost:9200/index1,index2/type/_search?ignore_unavailable
即使两个索引都不存在,也不会给出 404
| 归档时间: |
|
| 查看次数: |
2825 次 |
| 最近记录: |