# Query optimization

**URL:** <https://discuss.elastic.co/t/query-optimization/287559>\
**Category:** Elasticsearch\
**Created:** [October 25, 2021, 9:43am UTC](https://discuss.elastic.co/t/query-optimization/287559 "2021-10-25T09:43:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hadrienrsq](https://avatars.discourse-cdn.com/v4/letter/h/9d8465/32.png) [@hadrienrsq](https://discuss.elastic.co/u/hadrienrsq)\
**Post date:** [October 25, 2021, 9:43am UTC](https://discuss.elastic.co/t/query-optimization/287559/1 "2021-10-25T09:43:44Z")

</div>

Dear community,

I am pretty brand new to Elasticsearch and am looking to perform some sort of two steps query on one index. Indeed, the items in the index have what we call a cli\_ID attribute, which I would like to pre-filter the data on, and then perform an embedding similarity calculation (that could take some time) only on the items that match the first query.

Plus I would need to retrieve the scores associated with the embedding calculation exclusively.

I have implemented a solution using the post-filter option of Elasticsearch, however, it does not provide the score associated with the second query (embedding similarity calculation)

```auto
query_body = {
    "query": {"wildcard": { "client_ID" : "*"+cli_ID+"*" }},
    "post_filter": { 
        "bool": {
          "must": [
            /: query for the embedding calculation goes here. :/
          ]
        }
    }
}

```

This is a test using the post\_filter option but definitely does not fit our use case completely.

> <https://stackoverflow.com/questions/33650870/function-score-inside-the-post-filter-query-elasticsearch>

This link indicates that the post-filter can't provide the score using a filter option.

So my question is a little open, but I would really appreciate some guidance towards whatever solution that :

- Helps me prefilter the items in the index by client-ID
- Then compute the embedding similarity on those items
- Let me access the scores that are produced in the second query;

Thank you for your help in advance;

---

<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:** [November 22, 2021, 9:43am UTC](https://discuss.elastic.co/t/query-optimization/287559/2 "2021-11-22T09:43:46Z")

</div>

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