Tuning ranking in search result

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({
                        "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!

I recommend read articles like this:

In resume:

There are three main factors for a document's score in a given search.

TF (term frequency) – The more a term appears in a single field, the more relevant it is.
IDF (inverse document frequency) – The more documents have the search term, the less relevant it is.
Field Length – Smaller fields are naturally more relevant than larger fields.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.