# The term(s) filter and the standard analyzer

**URL:** <https://discuss.elastic.co/t/the-term-s-filter-and-the-standard-analyzer/47803>\
**Category:** Elasticsearch\
**Created:** [April 19, 2016, 2:50pm UTC](https://discuss.elastic.co/t/the-term-s-filter-and-the-standard-analyzer/47803 "2016-04-19T14:50:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpblair](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jpblair](https://discuss.elastic.co/u/jpblair)\
**Post date:** [April 19, 2016, 2:50pm UTC](https://discuss.elastic.co/t/the-term-s-filter-and-the-standard-analyzer/47803/1 "2016-04-19T14:50:27Z")

</div>

I have a document type that contains an array of objects about a person, one of which is their name. For example:

```
"creators":[
	{
		"id":"john.doe",
		"name":"John Doe"	
	},
	{
		"id":"jane.smith",
		"name":"Jane Smith"
	}
]

```

I want to have a filter that limits search results based on user input matching `creators.name`. Currently, I'm using the `term` filter. However, the standard analyzer only creates tokens for (to use the first example) "John" and "Doe", but NOT "John Doe", so my current method only works for "John" or "Doe", but not "John Doe". I considered using the `terms` filter instead and parsing the input based on whitespace, but then that would also match "John Smith", which is not ideal.

Is there a different way I should be querying, or do I need to use a different analyzer that would also treat "John Doe" as a token? And would these approaches properly address people with more than 2 names? Thanks.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [April 19, 2016, 3:55pm UTC](https://discuss.elastic.co/t/the-term-s-filter-and-the-standard-analyzer/47803/2 "2016-04-19T15:55:31Z")

</div>

Hi,

there are a few options here, depending on what else you want to do with that field. First, if you require exact matching of the name field, the field should probably be index as `"index" : "not_analyzed"`. That way you can use a 'term' query/filter and it will only match if it is exact. If, on top of that, you want _some_ analysis like lowercasing but no tokenization you can [roll your own analyzer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-custom-analyzer.html), for example using the [KeywordTokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-keyword-tokenizer.html) and then add lowercasing on top.  
If you also need the name in `creator.name` to be full-text searchable (e.g. find all `Smith` persons), you can index the same field in multiple ways, using the [fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html) parameter when setting up the mappings.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![jpblair](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jpblair](https://discuss.elastic.co/u/jpblair)\
**Post date:** [April 19, 2016, 5:38pm UTC](https://discuss.elastic.co/t/the-term-s-filter-and-the-standard-analyzer/47803/3 "2016-04-19T17:38:33Z")

</div>

Thanks for your reply. I still want the user to be able to provide just one of the names, so I wouldn't want to _only_ have the exact match. I guess that's where the `fields` parameter could come in. Basically what would be ideal is for it to be tokenized as `["John","Doe","John Doe"]` (or perhaps just the lowercased versions of those), but perhaps that's not possible without going under the hood to create my own analyzer/create multiple mappings.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [April 20, 2016, 8:27am UTC](https://discuss.elastic.co/t/the-term-s-filter-and-the-standard-analyzer/47803/4 "2016-04-20T08:27:25Z")

</div>

Okay, so you could try indexing both an analyzed and a non-analyzed version of the name using multi-fields and then query on both fields. That should already rank exact matches higher in your results. You could also try boosting the not-analyzed field if that alone doesn't help.

---

<div class="post-metadata">

**Author:** ![jpblair](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jpblair](https://discuss.elastic.co/u/jpblair)\
**Post date:** [April 25, 2016, 9:22pm UTC](https://discuss.elastic.co/t/the-term-s-filter-and-the-standard-analyzer/47803/5 "2016-04-25T21:22:58Z")

</div>

I saw another example of this where the ["match phrase" query](https://www.elastic.co/guide/en/elasticsearch/guide/current/phrase-matching.html) was used. Perhaps this would work? The only problem is that this is part of a filter, rather than a query.

---

<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:** [July 5, 2017, 10:56pm UTC](https://discuss.elastic.co/t/the-term-s-filter-and-the-standard-analyzer/47803/6 "2017-07-05T22:56:24Z")

</div>


