Give document fields different priority in search
Solution 1
Here is update for newer Elasticsearch versions. Query like this should boost results depending on respective fields content:
GET /_search
{
"query":{
"simple_query_string" : {
"query": "ABC",
"fields": [
"field2^3",
"field3^2",
"field1^1"]
}
}
}
Pay attention to "^3" after field2, this will boost results, so if "ABC" is found in all fields, they will be sorted as:
- doc with field2 containing "ABC"
- doc with field3 containing "ABC"
- doc with field1 containing "ABC"
Solution 2
Use a boost query and weight the fields in accordance with the prioritization you desire: https://www.elastic.co/guide/en/elasticsearch/guide/current/_boosting_query_clauses.html
user548936
Updated on August 05, 2022Comments
-
user548936 over 1 year
I have the following query:
'{"query": {"query_string": {"query": "ABC"}'
this will search all fields in given index\type ex. Mytype has field1, field2, field3 this will match "ABC" to field1, field2, field3
Equal value is placed on the 3 fields I need to prioritize the field ranking so let's say the priority should be field2, field3, field1
How do I modify my search to set the field ranking/priority?
In my research I saw _score but that looks like its used to prioritize each doc instead of the fields.
-
user548936 over 8 yearsbetter ex. using the field priority from above, lets say doc1 has a match with field3 and doc2 has a match with field2. even though doc1 and doc2 match, i need doc2 to have a higher score than doc1
-
-
N.K about 6 yearscan we use the same with Nest ?
-
Andriy Lesyuk almost 2 yearsWhich version Elasticsearch supports that?
-
Ewoks almost 2 yearssorry, 3y later, I don't remember it :(