Elasticsearch search scenario possibility?


(Vatsal Patel) #1

Hi,
I want to search data with below possibility?
I have document like below format.

PUT myindex/mytype/1
{
"status":"on",
"location": [ -73.983, 40.719 ]
}

PUT myindex/mytype/2
{
"status":"on",
"location": [ -73.983, 40.715]
}

PUT myindex/mytype/2
{
"status":"off",
"location": [ -73.983, 40.719]
}

Now, I want to sort the data based on status,
Case : if user status is "on" and if he is the closest then it should list first. and if user status is "off" and if he is near then it should display bottom of the list.

The final result will show people who are closest to me and are “on” and then when there is no more “on” person, the list starts with closest professionals who are not available.
Is it possible to get the result like this.? Thank you.


(Mark Walkom) #2

Yes, you'd need to do a filter and then a geo distance query after that, but it should be possible!


(Vatsal Patel) #3

hi warkolm,
Thank you for your reply . Can you please give me little bit more explain on that.Currently i am doing the same as you suggest. But i got result for only status="on" users and also they are sort by distance.
But i need those user's whose status is "off" and also sort by distance for them.
IS there any if else condition for query?.


(system) #4