我有两个索引:
首先,questions
有嵌套字段answers
。第二,articles
没有此字段。
我尝试通过多个索引搜索:
{
"index": "questions, articles",
"body":{
"query":{
"bool":{
"must":{
"nested":{
"path": "answerswer",
...
}
}
}
}
}
}
,得到错误"query_parsing_exception: [nested] failed to find nested object under path [answer]"
如何搜索没有错误,当一个索引有嵌套字段,但另一个没有?
我认为您需要使用indices
查询,并为每个索引使用不同的查询。像这样:
GET /questions,articles/_search
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"indices": {
"indices": [
"questions"
],
"query": {
"nested": {
"path": "answerswer",
"query": {
"term": {
"text": "bla"
}
}
}
}
}
},
{
"match_all": {}
}
]
}
},
{
"term": {
"some_common_field": {
"value": "whatever"
}
}
}
]
}
}
}