Bag-of-words matching

Hello.

there is a very simple thing I have been trying to do with ES, and only managed via a workaround:
given a query and a document field, match all the query's terms with all the field's terms.
In other words :

  1. the query's terms are a subset of the field's
  2. the field's terms are a subset of the query's

Requirement 1) is satisfied by using an and operator in a match query. But I have not been able to find a way for 2).

They only way I managed to achieve this so far is by leveraging highlight and requiring that all of the string is highlighted (in my application logic)

Is there another way?
Example

PUT bananas/banana/1
{ "name" : "banana"}

PUT bananas/banana/2
{ "name" : "ripe banana"}


PUT bananas/banana/3
{ "name" : "not so ripe banana"}

GET bananas/_search
{
  "query" : {
    "match": { "_all": { "query": "ripe banana", "operator": "and" } }
  },
  "highlight" : {
    "fields" : { "*" : { } },
    "require_field_match": false
  }
}

# RETURNS (edited):

  "hits" : {
    "hits" : [
      {
        "_index" : "bananas",
        "_type" : "banana",
        "_id" : "3",
        "_score" : 0.5753642,
        "_source" : {
          "name" : "not so ripe banana"
        },
        "highlight" : {
          "name" : [
            "not so <em>ripe</em> <em>banana</em>"
          ]
        }
      },
      {
        "_index" : "bananas",
        "_type" : "banana",
        "_id" : "2",
        "_score" : 0.51623213,
        "_source" : {
          "name" : "ripe banana"
        },
        "highlight" : {
          "name" : [
            "<em>ripe</em> <em>banana</em>"
          ]
        }
      }
    ]
  }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.