Is it possible to use query_string as filter?


(Vicente de Rivera III) #1

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?

    "query": {
    "query_string": {
    "default_operator": "AND",
    "query": "attributes.itemType:Sword attributes.league:"Hardcore Perandus" shop.hasPrice:true shop.verified:YES"
    }
    }

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

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!


(Mark Walkom) #2

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.


(Vicente de Rivera III) #3

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!


(Adrien Grand) #4

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


(Vicente de Rivera III) #5

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

Does this only return documents that match the range condition?

{
    "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?


(Daniel Mitterdorfer) #6

This can be achieved with decay functions.


(Vicente de Rivera III) #7

@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.


(system) #8