# Terms lookup in DLS query

**URL:** <https://forum.search-guard.com/t/terms-lookup-in-dls-query/1479>\
**Category:** Search Guard\
**Created:** [May 8, 2019, 10:45am UTC](https://forum.search-guard.com/t/terms-lookup-in-dls-query/1479 "2019-05-08T10:45:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Berre](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.search-guard.com/andreas_berre/32/509_2.png) [@Andreas\_Berre](https://forum.search-guard.com/u/Andreas_Berre)\
**Post date:** [May 8, 2019, 10:45am UTC](https://forum.search-guard.com/t/terms-lookup-in-dls-query/1479/1 "2019-05-08T10:45:05Z")

</div>

Hi,

Ran into trouble after defining a terms lookup query as a part of a DLS filter. Query fails with type":“illegal\_state\_exception”,“reason”:“async actions are left after rewrite”. The lookup-query executes without issue if submitted directly with a non-DLS enabled user.

Are lookup queries supported?

Using search-guard-6:6.7.2-25.0, DLS def:

_dls_: {“terms”:{“somefield”:{“index”:“some-index”,“id”:“${attr.jwt.someproperty}”,“path”:“somepath”,“type”:“sometype”}}}’

response:  
{  
“error”:{“root\_cause”:  
[  
{“type”:“query\_shard\_exception”,  
“reason”:"failed to create query: { “terms” : { “somefield” : { “index” : “some-index”, “type” : “sometype”, “id” : “asdf, “path” : “somepath” }, “boost” : 1.0 }}”,“index\_uuid”:“sRhY1f7mQOu0tDTZMvM4YQ”,“index”:“some-other-index”}],  
“type”:“search\_phase\_execution\_exception”,  
“reason”:“all shards failed”,  
“phase”:“query”,  
“grouped”:true,  
“failed\_shards”:[  
{“shard”:0,  
“index”:“some-other-index”,  
“node”:“wCxy-6KbSoWrbDXCTtTvWQ”,  
“reason”:{“type”:“query\_shard\_exception”,  
“reason”:“failed to create query: { “terms” : { “somefield” : { “index” : “some-index”, “type” : “sometype”, “id” : “asdf”, “path” : “somepath” }, “boost” : 1.0 }}”,  
“index\_uuid”:“sRhY1f7mQOu0tDTZMvM4YQ”,  
“index”:“some-other-index”,  
“caused\_by”:{  
“type”:“illegal\_state\_exception”,  
“reason”:“async actions are left after rewrite”  
}  
}  
}  
]  
},  
“status”:400  
}

---

<div class="post-metadata">

**Author:** ![cstaley](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.search-guard.com/cstaley/32/463_2.png) [@cstaley](https://forum.search-guard.com/u/cstaley)\
**Post date:** [May 8, 2019, 11:11am UTC](https://forum.search-guard.com/t/terms-lookup-in-dls-query/1479/2 "2019-05-08T11:11:47Z")

</div>

Terms lookup is not supported in DLS. I have to admin the error message is not optimal here 🙂

Queries where remote calls are involved are not supported. This is currently:

- terms query with terms lookup
- geo\_shape query with indexed shapes
- percolate query

---

<div class="post-metadata">

**Author:** ![cstaley](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.search-guard.com/cstaley/32/463_2.png) [@cstaley](https://forum.search-guard.com/u/cstaley)\
**Post date:** [May 8, 2019, 11:11am UTC](https://forum.search-guard.com/t/terms-lookup-in-dls-query/1479/3 "2019-05-08T11:11:51Z")

</div>



---

<div class="post-metadata">

**Author:** ![Andreas\_Berre](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.search-guard.com/andreas_berre/32/509_2.png) [@Andreas\_Berre](https://forum.search-guard.com/u/Andreas_Berre)\
**Post date:** [May 9, 2019, 4:40am UTC](https://forum.search-guard.com/t/terms-lookup-in-dls-query/1479/4 "2019-05-09T04:40:40Z")

</div>

Thanks for the prompt reply. I will figure out some wiorkaround.

And yeah, the error msg could stand some improvement 🙂

-andreas

---

<div class="post-metadata">

**Author:** ![Andreas\_Berre](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.search-guard.com/andreas_berre/32/509_2.png) [@Andreas\_Berre](https://forum.search-guard.com/u/Andreas_Berre)\
**Post date:** [May 9, 2019, 8:40am UTC](https://forum.search-guard.com/t/terms-lookup-in-dls-query/1479/5 "2019-05-09T08:40:47Z")

</div>

@cstaley: btw, the docs ([Search Guard document-level security basics | Security for Elasticsearch | Search Guard](https://docs.search-guard.com/latest/document-level-security)) claim that DLS queries “supports the full range of the Elasticsearch query DSL”, might want to reference the limitations.

-andreas

---

<div class="post-metadata">

**Author:** ![jkressin](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.search-guard.com/jkressin/32/9_2.png) [@jkressin](https://forum.search-guard.com/u/jkressin)\
**Post date:** [May 9, 2019, 9:39am UTC](https://forum.search-guard.com/t/terms-lookup-in-dls-query/1479/6 "2019-05-09T09:39:33Z")

</div>

True, and thanks for pointing this out. We will add a “Limitations” section in the docs to make it more clear what you can and can’t do with DLS.

---

<div class="post-metadata">

**Author:** ![jkressin](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.search-guard.com/jkressin/32/9_2.png) [@jkressin](https://forum.search-guard.com/u/jkressin)\
**Post date:** [May 9, 2019, 1:00pm UTC](https://forum.search-guard.com/t/terms-lookup-in-dls-query/1479/7 "2019-05-09T13:00:08Z")

</div>

We’ve added a “Limitations” section to the DLS docs.

---

<div class="post-metadata">

**Author:** ![jkressin](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.search-guard.com/jkressin/32/9_2.png) [@jkressin](https://forum.search-guard.com/u/jkressin)\
**Post date:** [May 9, 2019, 1:00pm UTC](https://forum.search-guard.com/t/terms-lookup-in-dls-query/1479/8 "2019-05-09T13:00:15Z")

</div>


