How to extract relevant tags from docs?

Hi everyone,

First, sorry for my english.

To ask my question i will expose to you an example.

I have a type tags who contains list of tags :

"_source": {
    "name": "tablet-sony",
}
"_source": {
    "name": "tv-sony"
 }
"_source": {
     "name": "tablet-samsung"
}

Now I want to get tags from this query :

"query": "I have tv sony and tablet samsung",

And I want to extract only tags : "tv-sony" and "tablet-samsung" but not "tablet-sony"

What is the best way to make this condition ?

Thank's for your help.

You can totally use a bool query with two should clauses, one for "match": {"name":tv sony"} and one for "match": {"name": "tabled samsung"} but I don't know of anything offhand that does the natural language parsing to figure out that that English sentence is actually two queries.

Thank's for your help.

But I want a more generic query. Maybe by defined a score of each tags where the score is the distance between two words.
Here, the score of "tablet samsung" is better than "tablet-sony" because is more clothes.

It's possible to do something like that ?

Thank's again to your help.

I don't know something already written but if you are very adventurous you could implement a plugin to add a new query type. Have a look at match query. In particular what you are looking for is sort of like the phrase flavor of the match query but not quite because not all of the terms in the phrase have to be found.