0

I have configured an Elasticsearch index with two fields : "Name" and "Type". When I execute the query below, I don't get any result because "actor" is in the "Type" field.

{
  "query": {
    "multi_match": {
      "query": "johnny depp actor",
      "operator": "AND",
      "fields": [
        "name",
        "type"
      ],
      "tieBreaker": 0.7
    }
  }
}

Is there any way to execute a query with a number of words, and to get results even if some words are in the "Name" field and others in the "Type" field.

Thanks for you help !

Mahdi DIF
  • 159
  • 1
  • 10

2 Answers2

0

You can try with:

{
  "query": {
    "bool":{
      "should":[
        {"match_phrase":{"name":"johnny depp actor"}},
        {"match_phrase":{"type":"johnny depp actor"}},
        {"match_phrase":{"name":"johnny"}},
        {"match_phrase":{"name":"depp"}},
        {"match_phrase":{"name":"actor"}},
        {"match_phrase":{"type":"johnny depp actor"}},
        {"match_phrase":{"type":"johnny"}},
        {"match_phrase":{"type":"depp"}},
        {"match_phrase":{"type":"actor"}},
      ]
    }
  }
}
Josué Zatarain
  • 791
  • 6
  • 21
  • Thanks for you answer, it actually works, but if the user types "jean claude van damme actor " you will have to add all the combinations. – Mahdi DIF May 24 '16 at 16:47
0

I finally found a solution. For those who probably need it, the solution is to use cross-field, so that all terms must be present in at least one field for a document to match.

{
  "query": {
    "multi_match": {
      "query": "johnny depp actor",
      "type": "cross_fields",
      "operator": "AND",
      "fields": [
        "name",
        "type"
      ],
      "tieBreaker": 0.7
    }
  }
}
Mahdi DIF
  • 159
  • 1
  • 10