A
A
alehandroWEB2020-03-30 13:51:18
PHP
alehandroWEB, 2020-03-30 13:51:18

How to do precise and non-precise searches in Elasticsearch?

At the moment there is such a request:

$response = $client->search([
      'index' => 'shop',
      'type' => 'products',
      'body' => [
        '_source' => ['id'],
        'query' => [
          'bool' => [
            'must' => [
              'multi_match' => [
                'query' => $text,
                'fuzziness' => 'auto',
                'operator' => 'and',
                'fields' => ['name', 'description']
              ]
            ]
          ]
        ]
      ]
    ]);

it searches for non-exact matches in the name and description fields. How to add an exact match search on the article field?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iva3682, 2020-05-02
@iva3682

it is better to use query_string and the $text string to tokenize before that, removing stop words, making a query like word1 AND word2 AND word3 and so on. Can be copied with match_phrase. It is also not clear what kind of mapping you have, how tokenization occurs inside the elastic to search by the basis of the word (to find options with different endings, for example, BUCKETS, on request BUCKET). To search by exact match, if the article field has a numeric form or keyword, then you can use term, if the type is text, then use match, while the analyzer should not change the value of the field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question