# Functional filter on ES v 9.0.0, not working on v 8.18.0

**URL:** <https://discuss.elastic.co/t/functional-filter-on-es-v-9-0-0-not-working-on-v-8-18-0/377692>\
**Category:** Elasticsearch\
**Created:** [April 30, 2025, 10:32pm UTC](https://discuss.elastic.co/t/functional-filter-on-es-v-9-0-0-not-working-on-v-8-18-0/377692 "2025-04-30T22:32:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave\_espinosa\_qs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dave_espinosa_qs/32/143411_2.png) [@dave\_espinosa\_qs](https://discuss.elastic.co/u/dave_espinosa_qs)\
**Post date:** [April 30, 2025, 10:32pm UTC](https://discuss.elastic.co/t/functional-filter-on-es-v-9-0-0-not-working-on-v-8-18-0/377692/1 "2025-04-30T22:32:04Z")

</div>

Hello everyone,

After checking [this post](https://discuss.elastic.co/t/how-do-i-combine-multiple-filters-with-or-without-affecting-the-score/284349/2), I implemented a **filter** (in a v 9.0.0 Elasticsearch infrastructure) which looks as follows:

```bash
[
    {
        "bool": {
            "should": [
                {"term": {"metadata.provider.keyword": "SkillShare"}},
                {"term": {"metadata.provider.keyword": "EDX"}}
            ]
        }
    }
]

```

The previous filter works OK.

However I was asked to adapt it in a v 8.18.0 Elasticsearch infrastructure, and that filter is no longer working, i.e., I get not matches at the output.

Why?

BTW, I am using that filter in the following Python script:

```python
import time
import os
from langchain_huggingface.embeddings import HuggingFaceEmbeddings
from langchain_elasticsearch import ElasticsearchStore

index_name = "my_index_name"
myfilter = [
    {
        "bool": {
            "should": [
                {"term": {"metadata.provider.keyword": "SkillShare"}},
                {"term": {"metadata.provider.keyword": "EDX"}}
            ]
        }
    }
]

embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")

vector_db = ElasticsearchStore(
    es_url="https://4a15e4224aca4e99bac99a6582a4abab.us-central1.gcp.cloud.es.io:443",
    es_api_key="get_your_own_api_key",
    index_name=index_name,
    embedding=embeddings
)

# ---------------------------- SIMILARITY SEARCH -----------------------------------------
print("\n\nSIMILARITY SEARCH")

t1 = time.time()
results = vector_db.similarity_search(
    query="Skill: Typography Fundamentals; Job Title: Graphic Designer",
    k=2*number_of_recommendations,
    filter=myfilter
)
t2 = time.time()
for res in results:
    print(f"* {res.page_content} [{res.metadata}]")
    print(80*"-")
print("\n\nCompleted on {:.2f} seconds".format(t2-t1))

```

Why? What am I doing wrong? What would be the correct filter equivalence, for Elasticsearch v 8.18.0?

Thanks

---

<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:** [April 30, 2025, 11:54pm UTC](https://discuss.elastic.co/t/functional-filter-on-es-v-9-0-0-not-working-on-v-8-18-0/377692/2 "2025-04-30T23:54:32Z")

</div>



---

<div class="post-metadata">

**Author:** ![dave\_espinosa\_qs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dave_espinosa_qs/32/143411_2.png) [@dave\_espinosa\_qs](https://discuss.elastic.co/u/dave_espinosa_qs)\
**Post date:** [April 30, 2025, 11:55pm UTC](https://discuss.elastic.co/t/functional-filter-on-es-v-9-0-0-not-working-on-v-8-18-0/377692/3 "2025-04-30T23:55:21Z")

</div>

Using some free GenAI providers plus my own troublehooting, I think I got it:

- For ES v 9.0.0, the filter was:

```python
myfilter = [
    {
        "bool": {
            "should": [
                {"term": {"metadata.provider.keyword": "SkillShare"}},
                {"term": {"metadata.provider.keyword": "Seneca"}}
            ]
        }
    }
]

```

But for ES v 8.18.0, the filter is:

```python
myfilter = [
    {
        "bool": {
            "should": [
                {"term": {"metadata.provider.enum": "SkillShare"}},
                {"term": {"metadata.provider.enum": "Seneca"}}
            ],
            "minimum_should_match": 1
        }
    }
]

```

As mentioned by the AI itself:

_"For `metadata.provider`, the mapping shows:_

```json
"provider": {
    "type": "text",
    "fields": {
        "enum": { // This is your keyword field
            "type": "keyword",
            "ignore_above": 2048
        },
        // ... other subfields
    }
}

```

_Instead of the standard `.keyword` naming convention, your index uses `.enum` for the keyword subfield."_

Hence, this case is SOLVED now.

---

<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:** [May 1, 2025, 1:18am UTC](https://discuss.elastic.co/t/functional-filter-on-es-v-9-0-0-not-working-on-v-8-18-0/377692/4 "2025-05-01T01:18:11Z")

</div>


