Results not as expected while querying alias (execution plan of alias query?)

I have a problem with querying two indices using an alias.
A simple setup resembling mine could be like this:

ElasticVersion 1.7.5

I have two indices with a common alias. That is:

Index: Index1 
Alias: TestAlias

and

Index: Index2 
Alias: TestAlias

My query is like this:

{
  "query" : {
    "bool" : {
      "must" : [ {
        "some_plugin" : {
            "id" : <ID>,
        }
      } ]
    }
  }
}

The plugin retrieves the document with the ID and builds a query from the content in the found document.

My problem is, that if the ID is matching a document in "Index1", the results are found correct for the partial query executed on shards containing "Index1", but not for "Index2".
The query created for querying the shards containing "Index2" is, as if there were no document found with ID.
And opposite, if ID is in "Index2", then the partial query executed on "Index1", is as if no document with ID was found.

As I understand Aliases, it is the same as just using multiple shards, and thus I would expect the partial queries executed on "Index1" and "Index2" to be the same.

It seems like, the query is performed separately on the two indices, and then merged at a later point in time. I have however not been able to find documentation for this.

I hope someone out there can help me :slight_smile:

First of all, you should consider upgrading to a modern version of elasticsearch. The second issue is that since we cannot reproduce the issue due to some_plugin and incomplete reproduction, it's really hard to figure out if this is elasticsearch issue, plugin issue or request issue, but I will try.

What does the plugin doing and does it work on shard level or on the coordinating node? What do you get if you search using Index1,Index2 instead of using the alias name?

I am aware that v.1.7.5 is old and we have to upgrade, however this is not a small task.

According to some_plugin lets say the mappings contains

"mappings":{
   "name":string
}

where each document can have multiple names. The plugin then basically takes the names from the specified documentId, and creates a SHOULD with the names, to find documents containing some of the same names.

Using the comma notation is giving me the same results.

When the code comes to BoolQueryParser.parse() the parseContext is already one of the specific indices, instead of the alias, which I am querying. Hence I suspect that the query is execute on each index, and then afterwards merged in some sort of way.

  • the plugin is installed on each node

So i guess it is also a matter of understanding how a query is executed when using aliases - maybe the behaviour is as expected, if it is executed on each index before getting merged?

I think the question is how the plugin is doing this. If the plugin is open source, I can take a look at it. Otherwise, I think the more productive approach would be to contact the author of this plugin.

My plugin was working on shardlevel, and was thus quering the shards with a context. This context was the specific index.
I managed to make a work-a-round, to solve my issue.

Thanks for the help @Igor_Motov.

I will close this discussion

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