Elasticsearch-dsl-py: Term queries don't work with uuids

Created on 15 Aug 2017  路  4Comments  路  Source: elastic/elasticsearch-dsl-py

I am trying to query documents using the term query type to filter documents that have a field that matches a specific uuid value. This is the statement I am using:

query = search.query('term', id_field=uuid_value)

but it isn't returning any hits when I execute the query

Most helpful comment

As @WisdomPill say, you really need to be using the keyword mapping for that field, if you are using text then match might return false positives in some scenarios.

All 4 comments

what is the mapping for that field? In order for this to work the id_field would have to be mapped at type: keyword. If you haven't specified any mappings than it is mapped as text with a .keyword subfield which you can use. Try search = search.query('term', id_field__keyword=uuid_value)

If that doesn't work please provide the mappings and also the entire code since I am not sure from your example what is query and search and how you use it. Thanks!

It didn't work with __keyword, I'm using 'match' instead. I know that this type of query checks whether a string is contained in the field but since my id_field doesn't vary in length I think that should fix it. I didn't try setting the field as a keyword though

Hi @MauriJHN you should use keyword in your field in order to use the term query. From a performance stand point it's better to use keyword and term query for searching for the exact string. The __keyword would work only if your using if your field datatype is text. Can you please post your mapping?

As @WisdomPill say, you really need to be using the keyword mapping for that field, if you are using text then match might return false positives in some scenarios.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vmogilev picture vmogilev  路  4Comments

quasiben picture quasiben  路  4Comments

berinhard picture berinhard  路  3Comments

abuzakaria picture abuzakaria  路  4Comments

beanaroo picture beanaroo  路  4Comments