A
A
Alexander Antonov2019-06-26 23:37:17
elasticsearch
Alexander Antonov, 2019-06-26 23:37:17

How to search by occurrence in a string in ElasticSearch?

How to change the mapping/index so that the query #1("Ivan") finds the record "Ivanova Olga Ivanovna"?
Index:

PUT /test
{
   "mappings": {
     "properties": {
     "title": {
       "type": "text"
     }
     }
   }
 }

PUT /test/_doc/1
{
  "title": "Иванова Ольга Ивановна",
}

Query #1 that doesn't find anything:
GET /test/_search
{
  "query": {
    "multi_match": {
      "query": "иван",
      "fuzziness": 1,
      "fields": ["title"]
    }
  },
  "highlight": {
    "fields": {
      "title": {}			
    }
  }
}

Request #2, by which it finds:
GET /test/_search
{
  "query": {
    "multi_match": {
      "query": "иванов",
      "fuzziness": 1,
      "fields": ["title"]
    }
  },
  "highlight": {
    "fields": {
      "title": {}			
    }
  }
}

RESPONSE:
"highlight": {
                    "title": [
                        "<em>Иванова</em> Ольга Ивановна"
                    ]
                }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question