1
I’m starting to make queries with elasticsearch_dsl and I’m getting lost to returns my object by product name.
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, connections, Q
client = Elasticsearch([{'host': 'elk-site.kalunga.com.br', 'port': 80, 'use_ssl': False}])
res=client.get(index='produto', id='217928')
print(res['_source'])
Json exit made by id.
{
"produto":[
{
"CD_PRODUTO":"217928",
"DS_Classificacao":"Notebooks, Tablets & PCs",
"DS_Grupo":"Computadores",
"DS_Subgrupo":"Computadores PCs",
"NM_Fabricante_Fantasia":"HP",
"NM_Produto":"Computador Pav.A6510BR AMD X2 4050E 2.1ghz 1gb 160gb Dvd-rw HP CX 1 UN"
}
]
}
When I try to make the query using the search of Elasticsearch-dsl I get no return. What would be missing in the query ?
produto = 'Computador Pav.A6510BR AMD X2 4050E 2.1ghz 1gb 160gb Dvd-rw HP CX 1 UN'
s = Search(using=client)
result = s.query("match", query='Computador Pav.A6510BR AMD X2 4050E 2.1ghz 1gb 160gb Dvd-rw HP CX 1 UN', fields=['NM_Produto', 'body'])
print(result ['_source'])