问题
We have an application where you can follow keywords such as 'Ford Mustang' and 'Fly Rod'. However when you follow a keyword you can assign a range distance to it. For instance you might be willing to travel 500 miles for a '1969 Ford Mustang' but you may only be willing to travel 20 miles for a 'Fly Rod'.
I am trying to figure out the best type of query and how it would be structured so that we could say the following.
1.) Take all followed phrases and pull back the results from the documents where the distance is less than or equal to the max distance.
I could be following these phrases.
Phrase: 1969 Ford Mustang
Distance: 800 Miles
Phrase: Fly Rod
Distance: 20 Miles
Phrase: 2015 F-150
Distance: 300 Miles
We are trying to use a single ElasticSearch Query to pull back all of the results. Does anyone have an example of how to do something like this? I tried to use QueryString but that does not allow you to filter by distance or do any type of pagination and both are a requirement.
I also tried a multi_match but that would do OR on the words so if I was following 'Fly Rod' it would return documents with 'Hot Rod' and we do not want that. It seems to return them because the multi_match uses an OR on the query keywords.
This is out last major hurdle before releasing the website to the world but looking through all the different query types I cannot see how it would be done.
If anyone has an example of how something like this could be accomplished with ElasticSearch I would appreciate the direction/feedback. I am not afraid to read documentation or tutorials I just have been unable to find anything relevant to this situation.
We need both the distance and phrases to be used in the query. The only way I can see this working personally is a single query for each followed phrase but that is not acceptable for performance reasons. I could easily be following 100-1000 phrases and that many queries would take too much network time for performance even though ES is really quite fast.
来源:https://stackoverflow.com/questions/43245610/elasticsearch-multiple-phrases-multiple-distances