D
D
DimaSeleznev2012-11-08 14:52:45
Programming
DimaSeleznev, 2012-11-08 14:52:45

elasticsearch. Combined fields search

Hello Habr.
I use Elasticsearch to search CouchDB.
The search is carried out by full name. The database has an object with name fields. last, name .first, name.middle.
I'm looking like this:

{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "Петров Иван Сергеевич",
            "fields": [
              "name.last",
              "name.first",
              "name.middle"
            ]
          }
        }
      ]
    }
  },
  "filter": {},
  "from": 0,
  "size": 20
}



And everything seems to be fine, but when searching, the correspondence to each of the fields is checked in turn.
Those. the result will include all the Petrovs, then all the Ivans, then all the Sergeyevichs.
You need to somehow combine the name fields. last, name .first, name.middle and search on this combined field.
Does anyone know how to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wuron, 2012-11-08
@DimaSeleznev

Try something like this:

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {"name.last": "Петров Иван Сергеевич"}
        },
        {
          "match": {"name.first": "Петров Иван Сергеевич"}
        },
        {
          "match": {"name.middle": "Петров Иван Сергеевич"}
        }
      ],
      "minimum_number_should_match": 1
    }
  },
  "filter": {},
  "from": 0,
  "size": 20
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question