1
I’m trying to use the minimum_should_match
how are you in documentation
q = Q('bool',
must=[Q('match', title='python')],
should=[Q(...), Q(...)],
minimum_should_match=1
)
s = Search().query(q)
But when I include it in my query it returns nothing.
termo = 'Cartucho p/caneta tinteiro preto 301218 Pelikan CX 6 UN'
q = Q('bool', must=[Q('match', TermoBusca=termo)],minimum_should_match=1)
s = Search(using=es, index='produtos').query(q)
print(s.to_dict())
produtosEncontrados: list = s.execute()
for produto in produtosEncontrados:
print(produto.Descricao)
If I remove the parameter (minimum_should_match=1
) query returns results normally.
termo = 'Cartucho p/caneta tinteiro preto 301218 Pelikan CX 6 UN'
q = Q('bool', must=[Q('match', TermoBusca=termo)])
s = Search(using=es, index='produtos').query(q)
print(s.to_dict())
produtosEncontrados: list = s.execute()
for produto in produtosEncontrados:
print(produto.Descricao)
Exit:
Generated query:
{'query': {'match': {'TermoBusca': 'Cartucho p/caneta tinteiro preto 301218 Pelikan CX 6 UN'}}}
Exit:
- Cartridge p/pen ink cartridge black 301218 Pelikan CX 6 UN
- Cartridge p/pen royal blue 301176 Pelikan CX 6 UN
- Ink p/pen 30ml black 301051 Pelikan EN 1 UN
- Ink p/pen 30ml dark blue 301028 Pelikan EN 1 UN
- Cartridge p/pen blue cartridge CA32005A Crown BT 3 UN
- Cartridge p/pen black cartridge CA32005P Crown BT 3 UN
- Capricci silver YW32616S Crown CX 1 UN source pen
- Capricci black ink pen YW32616P Crown CX 1 UN
- Neutral Regent Source Pen YW39422N Crown CX 1 UN
- Cartridge p/Brother black LC3039BK Brother CX 1 UN
I’ve looked everywhere and I don’t understand what I’m doing wrong.
My intention is to filter through the field TermoBusca
100% of the term reported. As in the query below, only using the DSL.
termo = 'Cartucho p/caneta tinteiro preto 301218 Pelikan CX 6 UN'
query_body = {
"sort" : [
{ "Prioridade" : {"order" : "desc"}},
{ "CurvaABC" : {"order" : "desc"}},
"_score"
],
"query": {
"match": {
"TermoBusca": {
"query": termo,
"minimum_should_match": "100%"
}
}
},
"size": 60
}
result = es.search(index="produtos", body=query_body)
print()
for hit in result['hits']['hits']:
print(hit['_source']['TermoBusca'])
self.assertEqual(56, len(result['hits']['hits']))
Exit:
- Cartridge p/pen ink cartridge black 301218 Pelikan CX 6 UN
Have you seen this post ?
– Paulo Marques
@Paulomarques, had not seen, but he is also using the querys of Elasticsearch and not Elasticsearch DSL
– Marco Souza