I am not getting why I am not getting exact document match. I have specified different context for completion suggestion but I got different suggestions.
python #elasticsearch #completion suggestion.
I had inserted data using this code into elasticsearch index
[ code]
mapping ={
"mappings": {
"panels": {
"properties": {
"dealer": {
"type": "completion"
},
"county": {
"type": "completion",
"contexts": [{
"name": "dealername",
"type": "category",
"path": "dealername"
},
{
"name": "statename",
"type": "category",
"path": "statename"
}
]
},
"state": {
"type": "completion",
"contexts": [{
"name": "dealername",
"type": "category",
"path": "dealername"
}]
},
"dealername":{
"type": "keyword"
},
"statename":{
"type": "keyword"
},
"countyname":{
"type": "keyword"
},
"meid": {
"type": "text"
}
}
}
}
}
res = es.indices.create(index="autocomplete", ignore=[400], body=mapping)
print(res)
def insertstatewise():
rows = session.execute("SELECT dealer_name, statename, county_name, meid from analytics.nearest_reco_output_1")
i = 0
for row in rows:
i += 1
yield {
"_id": row["meid"],
"_index": "autocomplete",
"_type": 'panels',
"_source":
{
"dealer": {
"input": [row["dealer_name"]]
},
"state": {
"input": [row["statename"]],
"contexts": {
"dealername": [row["dealer_name"]]
}
},
"county": {
"input": [row["county_name"]],
"contexts": {
"dealername": [row["dealer_name"]],
"statename": [row["statename"]]
}
},
"dealername": row["dealer_name"],
"statename": row["statename"],
"countyname": row["county_name"],
"meid": row["meid"]
},
}
xp = bulk(es, insertstatewise())
when I am searching for completion suggestion of one field. I am not getting values with the same context I had specified in the query.
When I am querying with curl request I am getting results as
curl -X POST "192.168.14.120:9200/autocomplete/_search?pretty" -H 'Content-Type: application/json' -d'
{
"suggest": {
"county_suggestion_for_dealer": {
"prefix": "wo",
"completion": {
"field": "county",
"size": 10,
"contexts": {
"dealername": [{
"context": "dealer2"
}],
"statename": [{
"context": "NorthCarolina"
}]
}
}
}
}
}'
I had got result
{
"text" : "Wood",
"_index" : "autocomplete",
"_type" : "panels",
"_id" : "#############",
"_score" : 1.0,
"_source" : {
"dealer" : {
"input" : [
"dealer2"
]
},
"state" : {
"input" : [
"Tennessee"
],
"contexts" : {
"dealername" : [
"dealer2"
]
}
},
"county" : {
"input" : [
"Wood"
],
"contexts" : {
"dealername" : [
"dealer2"
],
"statename" : [
"Tennessee"
]
}
},
"dealername" : "dealer2",
"statename" : "Tennessee",
"countyname" : "Wood",
"meid" : "###########"
},
"contexts" : {
"dealername" : [
"dealer2"
]
}
}
elasticsearch not detecting 2nd context statename which I had passed with the query.
[ /code]
elasticsearch not detecting 2nd context statename which I had passed with the query.