In elasticsearch, I search some tags and sort them from the most matching to the least matching. It's ok.
However, my problem is about order of equal matching situations.
For example:
- I stored these tags: "tag1", "tag2", "tag3", "tag4", "tag5"
- I stored these tags: "tag6", "tag1"
- I stored these tags: "tag4", "tag3", "tag1"
- I stored these tags: "tag2", "tag1", "tag5", "tag7"
My search query:
{
"query" : {
"bool" : {
"must" : [
{
"terms" : {
"my_field" : ["tag4", "tag6"],
minimum_should_match : 1
}
},
{"term" : {"my_cityId" : 1}},
{"term" : {"my_townId" : 8}}
]
}
},
"sort" : [
{"_score" : "desc"},
{"my_topTime" : "asc"}
],
"from" : 0,
"size" : 5
}
It returns:
- "tag6", "tag1"
- "tag1", "tag2", "tag3", "tag4", "tag5"
- "tag4", "tag3", "tag1"
My search order is tag4 and then tag6. How can it be returned tag4 contained rows first and tag6 after?