# Problem with filter

**URL:** <https://discuss.elastic.co/t/problem-with-filter/268466>\
**Category:** Elasticsearch\
**Created:** [March 26, 2021, 10:21am UTC](https://discuss.elastic.co/t/problem-with-filter/268466 "2021-03-26T10:21:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![modesto](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@modesto](https://discuss.elastic.co/u/modesto)\
**Post date:** [March 26, 2021, 10:21am UTC](https://discuss.elastic.co/t/problem-with-filter/268466/1 "2021-03-26T10:21:05Z")

</div>

Hi community

I'm quite new to Elastic and have run into some obstacles.

I want to do a search on a specific company id, with filters, but can't it to work, although it works with query.

Why is that?

```auto
curl --location --request GET 'http://elastic1-test.server.com:9200/estransactionse*/_search?q=companyId:123&size=10&track_total_hits=true&pretty=true'

```

Works, get hits.

```auto
curl --location --request GET 'http://elastic1-test.server.com:9200/estransactionse*/_search?q=companyId:123&size=10&track_total_hits=true&pretty=true'
Works, get hits.
curl --location --request GET 'http://elastic1-test.server.com:9200/estransactionse*/_search?pretty' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query": {
        "bool": {
            "filter": {
                "term": { "companyId": "123" }
            }
        }
    }
}'

```

Doesn't work.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2021, 12:24pm UTC](https://discuss.elastic.co/t/problem-with-filter/268466/2 "2021-03-26T12:24:22Z")

</div>

Welcome!

Are you sure that you example is correct?  
I mean that with 123 that should behave the same in my opinion.

Anyway, that's because you are using a term query on a text field which is analyzed.  
Use a simple query string query if you want to mimic what the `q=` parameter is doing.

---

<div class="post-metadata">

**Author:** ![modesto](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@modesto](https://discuss.elastic.co/u/modesto)\
**Post date:** [March 26, 2021, 12:35pm UTC](https://discuss.elastic.co/t/problem-with-filter/268466/3 "2021-03-26T12:35:47Z")

</div>

Hi and thanks  
No, my bad, "123" is actually a base64 string.  
If I use a simple query string, I'll also get a calculated score (that I don't need), therefore I wanted to use filters.  
I'm now re-creating the indices, with companyId being of type `keyword` instead of `text`.  
Is that the right way to go?  
Thanks.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2021, 1:44pm UTC](https://discuss.elastic.co/t/problem-with-filter/268466/4 "2021-03-26T13:44:17Z")

</div>

Yes it is. Or if you don't want to aggregate or sort, you can use a `text` field with a `keyword` analyzer.

---

<div class="post-metadata">

**Author:** ![modesto](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@modesto](https://discuss.elastic.co/u/modesto)\
**Post date:** [March 26, 2021, 3:39pm UTC](https://discuss.elastic.co/t/problem-with-filter/268466/5 "2021-03-26T15:39:14Z")

</div>

Thanks, are there any performance implications to choose one over the other?  
It's an ID, so it won't be sorted by, but it could be so that I want all transactions for a certain companyId, would that be an aggregation?  
Besides your answer, I'm grateful for any links you can recommend on this topic.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2021, 7:41pm UTC](https://discuss.elastic.co/t/problem-with-filter/268466/6 "2021-03-26T19:41:09Z")

</div>

> [@modesto](#):
>
> but it could be so that I want all transactions for a certain companyId,

So that's a search. The keyword datatype also generates other data structures on disk to run fast aggs and sort, called doc values. Here you don't need that so using a text type would probably be better in term of disk space. It does not change anything IMO regarding the response time.

---

<div class="post-metadata">

**Author:** ![modesto](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@modesto](https://discuss.elastic.co/u/modesto)\
**Post date:** [March 26, 2021, 8:19pm UTC](https://discuss.elastic.co/t/problem-with-filter/268466/7 "2021-03-26T20:19:16Z")

</div>

Great, thanks for the input, will read more on this. Have a great weekend

---

<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 23, 2021, 8:20pm UTC](https://discuss.elastic.co/t/problem-with-filter/268466/8 "2021-04-23T20:20:05Z")

</div>

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