Hi,
I don't see documentation for searching from .raw fields.
I'd like to search following:
{
"match": {
"content.raw": "Northern Ireland"
}
}
DSL alternative:
s.query = Q('bool', must=[Q('match', content.raw='python'), Q('match', body='best')])
It gives me error on content.raw part. Is there any way? or shall I use low-level client (elasticsearch-py) in this case?
Hi,
The query you want to execute is, perfectly valid; the only problem is that python doesn't allow . in the keyword argument name. To get around that the dsl library allows you to use __ (double underscore) instead:
s.query = Q('bool', must=[Q('match', content__raw='python'), Q('match', body='best')])
which should work.
Not, however, that the .raw field is typically not_analyzed (or keyword in elasticsearch 5.x) which means it doesn't support many queries - as in you won't get back any results unless you are doing an exact match. To make this explicit I like to use term query instead of match (explicit is better than implicit), also you don't have to construct the bool query yourself as the library can do that for you:
s = s.query('term', content__raw='python').query('match', body='test')
Hope this helps.
Most helpful comment
Hi,
The query you want to execute is, perfectly valid; the only problem is that python doesn't allow
.in the keyword argument name. To get around that the dsl library allows you to use__(double underscore) instead:which should work.
Not, however, that the
.rawfield is typicallynot_analyzed(orkeywordin elasticsearch 5.x) which means it doesn't support many queries - as in you won't get back any results unless you are doing an exact match. To make this explicit I like to usetermquery instead ofmatch(explicit is better than implicit), also you don't have to construct theboolquery yourself as the library can do that for you:Hope this helps.