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

**URL:** <https://discuss.elastic.co/t/results-not-as-expected-while-querying-alias-execution-plan-of-alias-query/162680>\
**Category:** Elasticsearch\
**Created:** [January 2, 2019, 3:40pm UTC](https://discuss.elastic.co/t/results-not-as-expected-while-querying-alias-execution-plan-of-alias-query/162680 "2019-01-02T15:40:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JF2018](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@JF2018](https://discuss.elastic.co/u/JF2018)\
**Post date:** [January 2, 2019, 3:40pm UTC](https://discuss.elastic.co/t/results-not-as-expected-while-querying-alias-execution-plan-of-alias-query/162680/1 "2019-01-02T15:40:05Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 2, 2019, 4:47pm UTC](https://discuss.elastic.co/t/results-not-as-expected-while-querying-alias-execution-plan-of-alias-query/162680/2 "2019-01-02T16:47:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![JF2018](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@JF2018](https://discuss.elastic.co/u/JF2018)\
**Post date:** [January 2, 2019, 5:14pm UTC](https://discuss.elastic.co/t/results-not-as-expected-while-querying-alias-execution-plan-of-alias-query/162680/3 "2019-01-02T17:14:55Z")

</div>

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.

> <https://github.com/lemonJun/ESHunt/blob/master/src/main/java/org/elasticsearch/index/query/BoolQueryParser.java>

- 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?

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 2, 2019, 6:22pm UTC](https://discuss.elastic.co/t/results-not-as-expected-while-querying-alias-execution-plan-of-alias-query/162680/4 "2019-01-02T18:22:29Z")

</div>

> [@JF2018](#):
>
> The plugin then basically takes the names from the specified documentId

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.

---

<div class="post-metadata">

**Author:** ![JF2018](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@JF2018](https://discuss.elastic.co/u/JF2018)\
**Post date:** [January 7, 2019, 2:44pm UTC](https://discuss.elastic.co/t/results-not-as-expected-while-querying-alias-execution-plan-of-alias-query/162680/5 "2019-01-07T14:44:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 4, 2019, 2:44pm UTC](https://discuss.elastic.co/t/results-not-as-expected-while-querying-alias-execution-plan-of-alias-query/162680/6 "2019-02-04T14:44:12Z")

</div>

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