0

I've been struggling to make my search work as expected, mainly because I don't know what kind of query I should make to fullfill my needs.

Essentially, what I am looking for, is that the results ideally would only include posts that include every term, but also keep fuzziness applied.

For example, if I look for the term '215 tires' it should bring results like:

  • 215 tires
  • 217 tires
  • 225 tires
  • 215 tire
  • ...

I am in the process of creating an app and have been learning too many stuff, and Elasticsearch is just a part of it, but it is HUGE. I've done some testing but looks like I am missing something.

Based on my understanding, I would expect something like the following query to work:

$query = array(
  'bool' => array(
    'should' => array(
      array(
        'multi_match' => array(
        'query'     => '',
        'fields'    => $search_fields,
        'boost'     => apply_filters( 'ep_match_boost', 2, $search_fields, $args ),
        'fuzziness' => 1,
        'operator'  => 'and',
      ),
   ),
);

Obviously I am doing something wrong, because I am not getting the results I am expecting, eg if I search '215 tires' I am getting results also for '215' alone, without any mention of the word 'tires'.

I experimented a lot by the most famous trial and error technique but it bear no fruit. Any help?

scooterlord
  • 15,124
  • 11
  • 49
  • 68
  • What type datatype is stored in `$search_fields`? – Nemo Aug 12 '20 at 12:43
  • @Nemo Not really sure, using default ElasticPress settings though. No matter the datatype, this query is based on the original query ElasticPress does, so I guess this is not the thing causing the issue. – scooterlord Aug 12 '20 at 13:16

1 Answers1

0

I am relatively new to ES, but from the look of you question you want probably want to look at termsbut terms cannot be used with text datatypes as analyzers can sometime change words if you want a solution that is more robust then have a look at score by word position, here is a question that was asked, I think it might solve your problem.

Nemo
  • 152
  • 11