# Filter query not working

**URL:** <https://community.pinecone.io/t/filter-query-not-working/2534>\
**Category:** General\
**Tags:** semantic-search, vector-database\
**Created:** [July 4, 2023, 10:14am UTC](https://community.pinecone.io/t/filter-query-not-working/2534 "2023-07-04T10:14:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cvenkatesh](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@cvenkatesh](https://community.pinecone.io/u/cvenkatesh)\
**Post date:** [July 4, 2023, 10:14am UTC](https://community.pinecone.io/t/filter-query-not-working/2534/1 "2023-07-04T10:14:05Z")

</div>

Problem: Query does not return result when filter is applied. Returns results fine when the filter is not mentioned in the query. Metadata has filters and no apparent semantic issues.

This does not work even when i use the pinecone console client to upsert and query data. Shows the same behavior. This is the case even with the sample data shown in the documentation. i’ve run out of ideas. Any help is appreciated.  
Upsert JSON

```auto
{
  "vectors": [
    {
      "id": "example-vector-1",
      "values":[....]
      "metadata": {
        "genre": "documentary",
        "year": 2019
      }
    }
  ]
}

```

Query JSON

```auto
{
  "vector": [...
  ],
  "topK": 5,
  "includeMetadata": true,
  "includeValues": false,
  "namespace": "",
  "filter":{
    "genre":{"$eq":["documentary"]}
  }
}

```

Tried other query combinations for filters like $in and without the operator . The query returns results if i remove the filter section.  
Any help is much appreciated.

---

<div class="post-metadata">

**Author:** ![dra](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/dra/32/171_2.png) [@dra](https://community.pinecone.io/u/dra)\
**Post date:** [July 5, 2023, 1:13am UTC](https://community.pinecone.io/t/filter-query-not-working/2534/2 "2023-07-05T01:13:38Z")

</div>

Hi @cvenkatesh

Your query structure appears to be correct, but it seems that your filter section is expecting a direct comparison, while an array (list) is provided instead.

In your filter, you have:

```auto
"filter": {
  "genre": {
    "$eq": ["documentary"]
  }
}

```

Here, the “$eq” operator is used for direct comparisons and typically does not expect an array (in this case, “documentary” is within an array). Try changing your query filter to:

```auto
"filter": {
  "genre": {
    "$eq": "documentary"
  }
}

```

This is likely to yield the expected results, as it’s directly comparing the genre to the string “documentary”.

If the filter notation is incorrect, you might expect to see an error message like the following: `"message": "the $eq operator must be followed by a string, boolean or a number, got [\"documentary\"] instead",`

Please check this part and try again. I hope this helps! Let me know if you need any further assistance.

---

<div class="post-metadata">

**Author:** ![cvenkatesh](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@cvenkatesh](https://community.pinecone.io/u/cvenkatesh)\
**Post date:** [July 5, 2023, 1:36am UTC](https://community.pinecone.io/t/filter-query-not-working/2534/3 "2023-07-05T01:36:07Z")

</div>

@dra thanks for responding. My bad. I made a mistake in copy pasting and editing the payload. It does not work even with the proper $in or $eq syntax. I tried it a friend’s database. same result. Its not working for him as well. Attaching screenshots. Again, thanks for your help.

```auto
{
  "vector": [...],
  "topK": 5,
  "includeMetadata": true,
  "includeValues": false,
  "namespace": "",
  "filter":{
    "genre":{"$eq":"documentary"}
  }
}

```

 ![Screenshot 2023-07-05 at 7.01.42 AM](https://us1.discourse-cdn.com/flex020/uploads/pinecone/original/1X/edf9e4a039d2e38ef9f1e9d9dfcf80826a4cbc82.png)

---

<div class="post-metadata">

**Author:** ![cvenkatesh](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@cvenkatesh](https://community.pinecone.io/u/cvenkatesh)\
**Post date:** [July 5, 2023, 1:36am UTC](https://community.pinecone.io/t/filter-query-not-working/2534/4 "2023-07-05T01:36:57Z")

</div>

Same thing with a filter

 ![Screenshot 2023-07-05 at 7.02.37 AM](https://us1.discourse-cdn.com/flex020/uploads/pinecone/original/1X/d18387685b17de963f2499d0719655f36b814532.png)

---

<div class="post-metadata">

**Author:** ![dra](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/dra/32/171_2.png) [@dra](https://community.pinecone.io/u/dra)\
**Post date:** [July 5, 2023, 2:11am UTC](https://community.pinecone.io/t/filter-query-not-working/2534/5 "2023-07-05T02:11:02Z")

</div>

@cvenkatesh  
This is just a guess, but are you specifying “metadata\_config” when creating the Index?  
If “metadata\_config” is not appropriately set, the filter will cease to function.

> **[Manage indexes](https://docs.pinecone.io/docs/manage-indexes#selective-metadata-indexing)**
>
> In this section, we explain how you can get a list of your indexes, create an index, delete an index, and describe an index.To learn about the concepts related to indexes, see Indexes.⚠️WarningIndexes on the Starter (free) plan are deleted after 7...

Try recreating the Index without setting the “metadata\_config”.

I think it will look something like this:

```auto
{
    "metric": "cosine",
    "pods": 1,
    "replicas": 1,
    "pod_type": "p1.x1",
    "name": "test-index",
    "dimension": 8
}

```

---

<div class="post-metadata">

**Author:** ![cvenkatesh](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@cvenkatesh](https://community.pinecone.io/u/cvenkatesh)\
**Post date:** [July 11, 2023, 12:54pm UTC](https://community.pinecone.io/t/filter-query-not-working/2534/6 "2023-07-11T12:54:46Z")

</div>

@dra thanks very much. You were spot on and it fixed the problem… I had copy pasted the index creation code and forgot to change the metadata\_config. It did not strike me to check the index creation parameters when debguging this issue.  
You helped resolve this. Thanks much.
