Partial List Of Words Match in documents


(Becjit) #1

Hi,
The ask is different from partial matches using n gram.

Suppose I have three documents with a field called file_content with type String (Default Full Text Search enabled)

First Document
{ _id: 1, file_content: "I love tennis and cricket"}
Second document:
{ _id: 2, file_content: "tennis and football are very popular"}
Third document:
{_id: 3, file_content" "football and cricket are originated in england"}

Now if I search with a list of words such as [tennis,cricket,football] is it possible to get following result:
[
{_id:1, includes; ["tennis", "cricket"]}
{_id:2, includes; ["tennis", "football"]}
{_id:1, includes; ["football", "cricket"]}
]

Thanks in advance,


Match list in list
#2

Hi,
You should take a look at bool queries and minimum_should_match.
Here is what you can do :

GET /becjit/examples/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "file_content": {
              "query": "tennis",
              "_name": "tennis"
            }
          }
        },
        {
          "match": {
            "file_content": {
              "query": "football",
              "_name": "football"
            }
          }
        },
        {
          "match": {
            "file_content": {
              "query": "cricket",
              "_name": "cricket"
            }
          }
        }
      ],
      "minimum_should_match":3
    }
  }
} 

You get only results that match 2 queries (football, cricket, tennis) or more.
Each hit got a field "matched_queries" that gives name of queries (see field "_name") that matched the document.


(system) #3