I am trying to boost query by fields and then sort them by date :
multiMatchQuery.fields(columnSortOrder());
searchSourceBuilder.trackScores(true);
searchSourceBuilder.sort(new ScoreSortBuilder().order(SortOrder.DESC));
searchSourceBuilder.sort("updated_time",SortOrder.DESC);
When I execute it return result boost by column. I want to get result with combination of both Highest Filed order sort by date
Boost Order
Field_A^3
Field_B^2
Field_C^1
sample data:
{
"_source": {
"updated_time": "2020-01-04T01:00:06.870000Z",
"field_A": "Slovakia beyond",
"filed_B": "The properties in Slovakia are beyound...",
"Field_C": "Once you fix the relevance then sorting should work correctly."
}
{
"_source": {
"updated_time": "2020-02-04T01:00:06.870000Z",
"field_A": "**beyond** filed_A",
"filed_B": "The properties in Japan is high",
"Field_C": "Test description for filed_A"
}
{
"_score": 2.56865,
"_source": {
"updated_time": "2020-01-04T01:00:06.870000Z",
"field_A": "Test filed_B",
"filed_B": "**beyond** is search term in filed_B",
"Field_C": "Test description for filed_B"
}
{
"_source": {
"updated_time": "2020-02-04T01:00:06.870000Z",
"field_A": "Test filed_B",
"filed_B": "**beyond** is search term in filed_B Test for Feb",
"Field_C": "Test description for filed_B test for Feb"
}
{
"_source": {
"updated_time": "2020-02-04T01:00:06.870000Z",
"field_A": "Search Term filed_C",
"filed_B": " is the search term for lowest column",
"Field_C": "**beyond** Test description for filed_C "
}
suppose search term is "beyond" If search term is found in [field_A,field_B,filed_C] Expected Result is:
[first priority Field_A sort by date]
- Slovakia beyond Jan 2020
- beyond filed_A Feb 2020
[second priority Field_B sort by date]
- beyond is search term in filed_B Jan 2020
- beyond is search term in filed_B Test for Feb 2020
[Third priority Field_C sort by date]
- beyond Test description for filed_C Feb 2020
It could be because of this
So enable
track_scoresfor your query.Java API
Use trackScores with parameterised variation.
And
When I try with sample data, sorting by score also required.
Add this as first sort and then sort by DESC date. It works as below.
If search term is part of more than one field [
field1, field2, field3], then combined score will be calculated.