How do you call shingles in Python DSL?
This is a simple example that searches for a phrase in the "name" field and another one in the "surname" field.
import json
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, Q
def make_dsl_query(fields):
"""
Construct a query
"""
es_client = Elasticsearch()
my_query = Search(using=es_client, index="my_index", doc_type="my_type")
if fields['name'] and fields['surname']:
my_query = my_query.query(Q('bool', should=
[Q("match", name=fields['name']),
Q("match", surname=fields['surname'])]))
return my_query
if __name__ == '__main__':
my_query = make_dsl_query(fields={"name": "Ivan The Terrible", "surname": "Conqueror of the World"})
response = my_query.execute()
# print response
for hit in response:
print(hit.meta.score, hit.name, hit.surname)
1) Is it possible to use shingles? And how? I've tried many things and can't find anything in the documentation on it.
This would work in a normal Elasticsearch query, but apparently called in a different way in the Python DSL...
my_query = my_query.query(Q('bool', should=
[Q("match", name.shingles=fields['name']),
Q("match", surname.shingles=fields['surname'])]))
2) How do I pass fuzziness parameters to my match? Can't seem to find anything on it either. Ideally I would be able to do something like this:
my_query = my_query.query(Q('bool', should=
[Q("match", name=fields['name'], fuzziness="AUTO", max_expansions=10),
Q("match", surname=fields['surname'])]))