# How to require two analyzers to match terms AND positions in full-text searching?

**URL:** <https://discuss.elastic.co/t/how-to-require-two-analyzers-to-match-terms-and-positions-in-full-text-searching/144697>\
**Category:** Elasticsearch\
**Created:** [August 16, 2018, 10:55am UTC](https://discuss.elastic.co/t/how-to-require-two-analyzers-to-match-terms-and-positions-in-full-text-searching/144697 "2018-08-16T10:55:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkazez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkazez/32/25991_2.png) [@bkazez](https://discuss.elastic.co/u/bkazez)\
**Post date:** [August 16, 2018, 10:55am UTC](https://discuss.elastic.co/t/how-to-require-two-analyzers-to-match-terms-and-positions-in-full-text-searching/144697/1 "2018-08-16T10:55:38Z")

</div>

Hello, I have an Elasticsearch mapping in which one field, surname, is analyzed according to ngram and `phonetic` analyzers. I [previously](https://discuss.elastic.co/t/boolean-searching-a-multi-value-multi-field/138359) asked about how to ensure that BOTH queries match each surname, essentially so that the ngram results can be used to restrict the result set returned from the phonetic analyzers. [dadoonet](https://discuss.elastic.co/u/dadoonet) [suggested](https://discuss.elastic.co/t/boolean-searching-a-multi-value-multi-field/138359/2?u=bkazez) using nested documents, which I successfully did – tokenizing the field on the client side and passing it during import as separate documents.

However, we are now using a `query_string` query to query the full text of each record in parallel with some extracted data like years. We would like to be able to add the phonetic queries to this, but again using the same ngrams to restrict the result set.

Essentially, I think I "just" need the two analyzers (phonetic and ngram) to be run and to require at query time that the term positions match. Otherwise I would have to create a nested document for every word, which seems a bit like it will explode the document count.

I had a feeling that span queries would help but it doesn't look like those would work with query\_string. I also considered creating a custom phonetic plugin that creates different tokens that apply my ngram logic, but we are unfortunately very low budget and can't afford hosting plans that let us upload custom plugins.

Any ideas? Many thanks!

Ben

---

<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:** [September 13, 2018, 10:55am UTC](https://discuss.elastic.co/t/how-to-require-two-analyzers-to-match-terms-and-positions-in-full-text-searching/144697/2 "2018-09-13T10:55:43Z")

</div>

Closed on September 13, 2018, 10:55am UTC

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