doc1 = {"id":1,"text":"tonight"}
doc2 = {"id":2,"text":"tonight tonight"}
doc3 = {"id":3,"text":"tonight tonight tonight"}
doc4 = {"id":4,"text":"tonight and something else"}
doc5 = {"id":5,"text":"tonight and you"}
es.index(index="tonight", document=doc1)
es.index(index="tonight", document=doc2)
es.index(index="tonight", document=doc3)
es.index(index="tonight", document=doc4)
es.index(index="tonight", document=doc5)
Suppose I have the above documents indexed. When I use the below query:
data = json.dumps({
"query":{
"bool":{
"should":[
{
"match":{
"text": "tonight"
}
}
]
}
}
})
The hits returned in the order of "tonight tonight tonight", "tonight tonight","tonight", "tonight and you" and "tonight and something else". May I ask if there is a way to make "tonight" as the first hit returned with highest _score? In my real life usecase, I am conducting iterating throught the whole index to find out the most relevant text other than itself, and the document being searched should be returned as the first hit (most matched) if possible. Could someone please give me some ideas on how to query? Thank you!