# Multiple metadata filters not working

**URL:** <https://community.pinecone.io/t/multiple-metadata-filters-not-working/2851>\
**Category:** Support\
**Created:** [July 31, 2023, 10:11pm UTC](https://community.pinecone.io/t/multiple-metadata-filters-not-working/2851 "2023-07-31T22:11:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![terrence](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/terrence/32/622_2.png) [@terrence](https://community.pinecone.io/u/terrence)\
**Post date:** [July 31, 2023, 10:11pm UTC](https://community.pinecone.io/t/multiple-metadata-filters-not-working/2851/1 "2023-07-31T22:11:25Z")

</div>

When I hardcode my filters, everything works fine. When I put in variables, my filter always returns empty. Am I going about this wrong?

if ‘query’ in data: # Check if the request contains a ‘query’ field  
query = data[‘query’]  
# Capture the namespace  
namespace\_query = data.get(‘namespace\_query’)  
# Capture company name, type, story, and client name if they are provided in the request data  
company\_query = [data[‘company\_query’]  
] if ‘company\_query’ in data else   
type\_query = [data[‘type\_query’]] if ‘type\_query’ in data else   
story\_query = [data[‘story\_query’]] if ‘story\_query’ in data else   
client\_query = [data[‘client\_query’]] if ‘client\_query’ in data else

```
    my_inp_embed = get_embedding(query, engine="text-embedding-ada-002")

    # Define the filter for the Pinecone query
    filter = {}

    if company_query[0]:
        filter["company name"] = {"$in": company_query}
    if type_query[0]:
        filter["type of story"] = {"$in": type_query}
    if story_query[0]:
        filter["story title"] = {"$in": story_query}
    if client_query[0]:
        filter["client name"] = {"$in": client_query}

    print(f"Using filter: {filter}") # print out the filter for debugging

    res = index.query(
        vector=my_inp_embed,
        top_k=3,
        filter=filter,
        include_metadata=True,
        include_values=False,
        namespace=namespace_query
    ) ; My HTML matches up, I've debugged every possible way, but my filter is always empty.

```

---

<div class="post-metadata">

**Author:** ![ZacharyProser](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/zacharyproser/32/1146_2.png) [@ZacharyProser](https://community.pinecone.io/u/ZacharyProser)\
**Post date:** [October 18, 2023, 6:26pm UTC](https://community.pinecone.io/t/multiple-metadata-filters-not-working/2851/2 "2023-10-18T18:26:02Z")

</div>

Hi @terrence,

Thanks for your question, and I’m sorry you’re encountering this issue.

After reviewing your code and the [metadata filtering documentation](https://docs.pinecone.io/docs/metadata-filtering), I have a couple of recommendations to try out - hopefully one of these helps shake something loose:

- **Checking for Non-Empty Lists:** Try replacing the index-based check `if company_query[0]:` with `if company_query:` to prevent potential `IndexError` exceptions and to check for non-empty lists.
- **Debugging:** Print the `data` object to ensure it contains the expected values. This would help verify whether the variables are being populated as intended before being used to construct the filter expressions.
- **Key Names:** Ensure that the key names used in the filter object exactly match the key names used when inserting metadata into the Pinecone index. You’ve probably already done this, but any mismatch in key names will result in an empty filter.
- **Null Metadata Values:** Ensure that the fields in the request data do not contain null values for some unexpected reason, as this could lead to unexpected behavior

I hope this is helpful! Let me know if that changes anything and if you have any follow-up questions.
