# Similar result set for singular and plural query

**URL:** https://discuss.elastic.co/t/similar-result-set-for-singular-and-plural-query/102454
**Category:** Elasticsearch
**Created:** [October 2, 2017, 4:25pm UTC](https://discuss.elastic.co/t/similar-result-set-for-singular-and-plural-query/102454 "2017-10-02T16:25:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ParitoshBh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paritoshbh/32/22487_2.png) [@ParitoshBh](https://discuss.elastic.co/u/ParitoshBh)
#### Post date: [October 2, 2017, 4:25pm UTC](https://discuss.elastic.co/t/similar-result-set-for-singular-and-plural-query/102454/1 "2017-10-02T16:25:34Z")

</div>

Here's the problem, for search terms 'cats' and 'cat', I am trying to get similar results i.e. 'cats' should search for 'cat' internally. To solve this `minimal_english` seems like a good choice, and am using that as part of other settings (see below),

```
      $params['body']['settings'] = [
      'analysis' => [
        'analyzer' => [
          'shingle_analyzer' => [
            'tokenizer' => 'standard',
            'filter' => ['standard', 'lowercase', 'filter_stop', 'filter_shingle']
          ],
          'ngram_analyzer' => [
            'tokenizer' => 'ngram_tokenizer',
            'filter' => ['standard', 'lowercase']
          ],
          'stemmer_analyzer' => [
            'tokenizer' => 'standard',
            'filter' => ['standard', 'lowercase', 'filter_english_stemmer']
          ]
        ],
        'tokenizer' => [
          'ngram_tokenizer' => [
            'type' => 'edge_ngram',
            'min_gram' => 3,
            'max_gram' => 10,
            'token_chars' => ['letter', 'digit']
          ]
        ],
        'filter' => [
          'filter_stop' => [
            'type' => 'stop'
          ],
          'filter_shingle' => [
            'type' => 'shingle',
            'min_shingle_size' => 2,
            'max_shingle_size' => 3,
            'output_unigrams' => true,
            'filler_token' => ''
          ],
          'filter_english_stemmer' => [
            'type' => 'stemmer',
            'name' => 'minimal_english'
          ]
        ]
      ]
    ];

```

Here's the query being built,

```
               "query" => [
                "bool" => [
                  "must" => [
                    "multi_match" => [
                      "query" => $queryTerm,
                      'type' => 'most_fields',
                      'fields' => [
                        'animal.name.shinglefield',
                        'animal.name.ngramfield',
                      ],
                      'analyzer' => 'stemmer_analyzer'
                    ]
                  ],
                ]
              ],

```

I tried 3 different scenarios,

1. `filter_english_stemmer` as part of filter in `shingle_analyzer` - With this in place, a search for 'cats' still returns matches for 'cats' based on ngrams which makes sense since ngrams doesn't have `filter_english_stemmer` filter.
2. To overcome previous issue, I placed `filter_english_stemmer` as part of `ngram_analyzer` filter. But doing so resulted in no matches for 'cats'. Again, this makes sense since there's no shingle/ngram for either 'cats' or 'ats'.
3. As an alternative approach (and with settings shared above), I used `stemmer_analyzer` as part of `multi_match` query (`analyzer => 'stemmer_analyzer'`) and that query gave me similar results for 'cats' and 'cat'.

Now, my question is even though the last approach works but is it a good idea to use analyzer at query time? Is there a better way out?

Also, correct me if I am wrong but the `stemmer_analyzer` used in `multi_match` query works since the query 'cats' is reduced to 'cat' and then field specific analyzers are run? Is that how its working?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 30, 2017, 4:25pm UTC](https://discuss.elastic.co/t/similar-result-set-for-singular-and-plural-query/102454/2 "2017-10-30T16:25:37Z")

</div>

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