# Is it possible to use query\_string as filter?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-use-query-string-as-filter/43590>\
**Category:** Elasticsearch\
**Created:** [March 6, 2016, 4:08am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-query-string-as-filter/43590 "2016-03-06T04:08:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vicente\_de\_Rivera\_II](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vicente\_de\_Rivera\_II](https://discuss.elastic.co/u/Vicente_de_Rivera_II)\
**Post date:** [March 6, 2016, 4:08am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-query-string-as-filter/43590/1 "2016-03-06T04:08:32Z")

</div>

I use _query string_ but I actually only use it for boolean operations like,

1. is this field exist?

2. is this field contain this value or range of int values?

3. this field field contain exactly this string?

4. is this field true?

From what I understand, I should be using filter instead. However, I've invested into using the query string:

[http://exiletrade.github.io/](http://exiletrade.github.io/)

On this open source site we have. I've made an engined that uses a bunch of regex to translate the user input like:

```
gloves 50life (30fireres OR 10-20coldres)

```

into elastic _query string_. Note that I have no need for _scores_.

Any advice? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 6, 2016, 8:23pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-query-string-as-filter/43590/2 "2016-03-06T20:23:54Z")

</div>

It's possible. I don't think we'd cache the results for this as efficiently as we would if you use a filter for example.

---

<div class="post-metadata">

**Author:** ![Vicente\_de\_Rivera\_II](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vicente\_de\_Rivera\_II](https://discuss.elastic.co/u/Vicente_de_Rivera_II)\
**Post date:** [March 7, 2016, 5:31am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-query-string-as-filter/43590/3 "2016-03-07T05:31:04Z")

</div>

Actually we have a good use for ranked searches.

For example, a user would like to find:

`helmet 50life 10chaos`

This means, helmet that has around +50 to max life and costs around 10 orb of chaos.

The user would actually care if there's a helmet that's +49 life and is very cheap like 5 orb of chaos.

Would really appreciate any advice (or spoonfeed) of how might I achieve this.

Again, thanks!

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [March 8, 2016, 10:20am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-query-string-as-filter/43590/4 "2016-03-08T10:20:57Z")

</div>

You would probably need to parse such a query on the client side and then send a structured query to elasticsearch.

---

<div class="post-metadata">

**Author:** ![Vicente\_de\_Rivera\_II](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vicente\_de\_Rivera\_II](https://discuss.elastic.co/u/Vicente_de_Rivera_II)\
**Post date:** [March 14, 2016, 1:09pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-query-string-as-filter/43590/5 "2016-03-14T13:09:10Z")

</div>

Follow up question. Let's say that I use the range query:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html)

Does this only return documents that match the range condition?

```auto
{
    "range" : {
        "age" : {
            "gte" : 10,
            "lte" : 20,
            "boost" : 2.0
        }
    }
}

```

Is it possible to return documents that have an `age` of 9 but has lower score than documents with `age` of 10?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [March 14, 2016, 1:25pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-query-string-as-filter/43590/6 "2016-03-14T13:25:28Z")

</div>

This can be achieved with [decay functions](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-decay).

---

<div class="post-metadata">

**Author:** ![Vicente\_de\_Rivera\_II](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vicente\_de\_Rivera\_II](https://discuss.elastic.co/u/Vicente_de_Rivera_II)\
**Post date:** [March 16, 2016, 6:25am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-query-string-as-filter/43590/7 "2016-03-16T06:25:18Z")

</div>

@danielmitterdorfer thanks for the reply.  
I'm glad that scoring function would work with query\_strings; and I'm excited to use it on our project. Hopefully it won't get too complicated on writing up with the scoring function that would satisfy our domain requirement.

---

<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:** [July 5, 2017, 11:07pm UTC](https://discuss.elastic.co/t/is-it-possible-to-use-query-string-as-filter/43590/8 "2017-07-05T23:07:59Z")

</div>


