Lets say I have index with two text fields:
"properties" : {
"name" : {
"type" : "text"
},
"description" : {
"type" : "text"
}
}
I need to implement full text search by these two fields with priority. First by name, and after that by description. The point is that I don't need to search in description, if I have already found something by name. I can implement two queries, and check if search by name returns 0 result, than search by description. But is there way to implement it with single query?
UPD. My query is pretty simple:
"query": {
"bool": {
"should": [
{
"match": {
"name": {
"query": "some user input here",
"operator": "and"
}
}
},
{
"match": {
"description": {
"query": "some user input here",
"operator": "and"
}
}
}
]
}
}
The refined question is, how to group result of single query in two groups: those who match by name, and those who match by description? First group should be scored higher than second. I need to know total count for both groups to implement paging behavior in my application. So when first group is empty, I will show the second, but not only then. Otherwise I will hide the second group from user. Also there should be relevance(by provided analyzer) scoring within a group in order to provide reasonable results of search to users.