Phrase/ multi-worlds search

I am trying to implement a use case wherein a user can make a multi-words/ phrase search for 'product_name' field.

Assuming someone is searching for 'Richest Man', the following results should come:

  • The Richest Man in Babylon
  • Story of the Richest man
  • The richest man in the world
  • How to win the richest man

Search result must not include the following docs-

  • Richest woman and man
  • When a poor man becomes the richest

Here is the analyser that I wrote:
`
'settings' => [
'analysis' => [
'filter' => [
'autocomplete_filter' => ['type' => 'ngram', 'min_gram' => 1, 'max_gram' => 10]
],
'analyzer' => [
'autocomplete' => ['type' => 'custom', 'tokenizer' => 'standard', 'filter' => ['lowercase', 'autocomplete_filter']]
]
],
'index.max_ngram_diff' => 10
],
'mappings' => ['properties' => [
'product_name' => ['type' => 'text', 'analyzer' => 'autocomplete', 'search_analyzer', 'standard'],
]],

and I am using the following code, written in PHP to make a search request:

`
$params = [
'index' => ProductData::ELASTIC_INDEX,
'type' => ProductData::ELASTIC_TYPE,
'body' => [
'query' => ['match' => ['product_name' => ['query' => $requestVars['product_name']]]
],
]
];

$result = $this->client->search($params);
`

If I search for "richest m" or "hest man" I should get those 4 results. If I search for "richest", "ches" or "ma" I should be seeing all the results i.e. 6 documents.

However, the result that I am getting is unexpected and not the ones that I listed above.

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