How to wrap nested query with filter by _index field in ElasticSearch?

I have the following query
GET product,account/producttype,accounttype/_search
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"nested": {
"query": {
"bool": {
"should": [
{
"match": {
"keywords.keyword": {
"query": "search query"
}
}
},
{
"term": {
"keywords.keyword.keyword": {
"value": "search query"
}
}
}
]
}
},
"path": "keywords"
}
}
],
"filter": [
{
"term": {
"_type": {
"value": "producttype"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"multi_match": {
"query": "search query",
"operator": "or",
"fields": [
"accountName^1.5",
"description^0.8"
]
}
}
],
"filter": [
{
"term": {
"_type": {
"value": "accounttype"
}
}
}
]
}
}
]
}
}
}

When I run the above query I get this exception:

"index": "account", "caused_by": { "type": "illegal_state_exception", "reason": "[nested] failed to find nested object under path [keywords]" }

Inside index account there is no nested object called Keywords.

In the past Indices query was used to solve this issue, but now it's deprecated.

Now as the query above shows: I am using filtering by _index but it still gives me that error.

So, could you please guide me to get rid of that exception and get my query working?

PS:

I am using elasticsearch v5.1.1

Hi @SimpleCode,

Instead of filtering by index "product" in the query you can search only in index product by specifying only it in the URL:

GET product/producttype/_search
{
   ...
}  

Hope it helps.

Cheers,
LG

@luiz.santos

Thanks for reply

I have modified my question, my query will hit multiple indices. So I can't specify only one index I need to search inside two indices in the same query

@luiz.santos Hello, I'm also interested in the answer to this question.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.