Natural language query string - extract specific keywords for term filter


(mac2000) #1

Imagine that you have documents with fields like: title, description, city_name

Lets say that documents describe some events like Rubyconf, JavaOne, SQLPass and so on. Description of event can contain many occurrences of different city names.

And here is tricky part - user enter to search string: "Java London"

If document have many occurrences of London word in its description - it will be scored as good result which is not always true.

Is it possible to somehow extract keywords from query string and turn them into term filter (in this case by city_name) so actually we will search Java filtered by city_name: london?

Here is sample:

POST /events/event/1
{
    "title": "JavaOne 2015",
    "description": "Java conference in London and Berlin",
    "city_name": "London"
}

POST /events/event/2
{
    "title": "RubyConf 2015",
    "description": "Ruby conference in New York and London",
    "city_name": "New York"
}

POST /events/event/_search
{
    "_source": false,
    "query": {
        "query_string": {
           "query": "Java London"
        }
    },
    "highlight": {
        "pre_tags": ["["], 
        "post_tags": ["]"], 
        "fields": {
            "title": {},
            "description": {},
            "city_name": {}
        }
    }
}

Result of search will be both events, because second contains London in description. Desired result is only first event.

PS: I do know that I can search on specific fields and exclude description from search but it is not option at least I am trying to figure out is it possible at all

Thank you


(system) #2