# Ignore common terms in field-based query

**URL:** <https://discuss.elastic.co/t/ignore-common-terms-in-field-based-query/198285>\
**Category:** Elasticsearch\
**Created:** [September 5, 2019, 3:42pm UTC](https://discuss.elastic.co/t/ignore-common-terms-in-field-based-query/198285 "2019-09-05T15:42:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Daily](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/james_daily/32/51985_2.png) [@James\_Daily](https://discuss.elastic.co/u/James_Daily)\
**Post date:** [September 5, 2019, 3:42pm UTC](https://discuss.elastic.co/t/ignore-common-terms-in-field-based-query/198285/1 "2019-09-05T15:42:52Z")

</div>

Let's say I have a search that matches two inputs (first name and last name) against first name and last name fields in my index.

My index contains very clean data - good first names, good last names.

However, the data entry driving the search query has poor quality data. Often the first name may actually contain a prefix such as "Mrs." instead of a first name like "Jessica".

So I may encounter queries such as "First=Mrs, Last=Robinson".

I'd like to define a list of words such as "Mrs, Mr, Ms, Dr, Prof" where if those are given as the First Name to search for, I'd want my search to behave as if they passed null/blank for first name instead, and focus on searching for Last name exclusively. However if a good first name (ie not one of those words) is given, I'd want the search to treat first name and last name equally in weight.

Is this possible to do?

What I've tried:

- stop words / token filter: most advice I've found as in respect to the index / data ingestion phase, rather than cleaning up data inside a query.
- script template + conditional clauses: This seems close, but it seems like I can only consider a field's presence in a query rather than react to a specific set of values in that field when present

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [September 13, 2019, 2:19pm UTC](https://discuss.elastic.co/t/ignore-common-terms-in-field-based-query/198285/2 "2019-09-13T14:19:08Z")

</div>

How are you running the query currently? When a term is not found in a field, it doesn't contribute to the score so having tokens that never occur shouldn't be a big deal? Unless you are requiring that both the first name and the last name match?

Have you looked into configuring a `search_analyzer` on your `first_name` field that configures stop words?

---

<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 11, 2019, 2:19pm UTC](https://discuss.elastic.co/t/ignore-common-terms-in-field-based-query/198285/3 "2019-10-11T14:19:10Z")

</div>

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