# Problem with mapping and matchQuery

**URL:** <https://discuss.elastic.co/t/problem-with-mapping-and-matchquery/59975>\
**Category:** Elasticsearch\
**Created:** [September 7, 2016, 11:36am UTC](https://discuss.elastic.co/t/problem-with-mapping-and-matchquery/59975 "2016-09-07T11:36:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![uncleBens](https://avatars.discourse-cdn.com/v4/letter/u/a9a28c/32.png) [@uncleBens](https://discuss.elastic.co/u/uncleBens)\
**Post date:** [September 7, 2016, 11:36am UTC](https://discuss.elastic.co/t/problem-with-mapping-and-matchquery/59975/1 "2016-09-07T11:36:18Z")

</div>

Hi,

This is my index settings:

> {  
> "analysis":{  
> "filter":{  
> "simpleNGram\_filter":{  
> "type":"nGram", "min\_gram":2, "max\_gram":20  
> }  
> },"analyzer":{  
> "simple\_nGram\_analyzer":{  
> "type":"custom", "tokenizer":"simple\_ngram\_tokenizer", "filter":["lowercase"]}  
> },"tokenizer":{  
> "simple\_ngram\_tokenizer":{  
> "type":"nGram", "min\_gram":2, "max\_gram":5, "token\_chars":["whitespace", "letter", "digit"]}  
> }  
> }  
> }

This is my document mapping

> ```
> "mydocumentname" : {
> "properties" : {
>    
> "description" : {
> "type" : "string",
> "index" : "analyzed",
> "store" : "yes",
> "search_analyzer" : "simple_nGram_analyzer",
> "analyzer" : "simple_nGram_analyzer"
> } 
> }
> 
> ```
> 
> }

This is "Mark Twain" analysis:

> AnalyzeRequest request = (new AnalyzeRequest("myindex\_name").text("Mark Twain")).analyzer("simple\_nGram\_analyzer")

> ma  
> mar  
> mark  
> mark  
> ar  
> ark  
> ark  
> ark t  
> rk  
> rk  
> rk t  
> rk tw  
> k  
> k t  
> k tw  
> k twa  
> t  
> tw  
> twa  
> twai  
> tw  
> twa  
> twai  
> twain  
> wa  
> wai  
> wain  
> ai  
> ain  
> in

Problem is that querying for "rk tw" returns nothing:

> ```
> searchResponse = clientManager.getClient().prepareSearch(myindexname)
> .setQuery(matchQuery("description", "rk tw"))
> .execute().actionGet();
> 
> ```

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [September 8, 2016, 9:47am UTC](https://discuss.elastic.co/t/problem-with-mapping-and-matchquery/59975/2 "2016-09-08T09:47:10Z")

</div>

What version are you running?  
This works for me on 2.4:

```
DELETE test
PUT /test
{
   "settings": {
	  "analysis": {
		 "filter": {
			"simpleNGram_filter": {
			   "type": "nGram",
			   "min_gram": 2,
			   "max_gram": 20
			}
		 },
		 "analyzer": {
			"simple_nGram_analyzer": {
			   "type": "custom",
			   "tokenizer": "simple_ngram_tokenizer",
			   "filter": [
				  "lowercase"
			   ]
			}
		 },
		 "tokenizer": {
			"simple_ngram_tokenizer": {
			   "type": "nGram",
			   "min_gram": 2,
			   "max_gram": 5,
			   "token_chars": [
				  "whitespace",
				  "letter",
				  "digit"
			   ]
			}
		 }
	  }
   },
   "mappings": {
	  "doc": {
		 "properties": {
			"description": {
			   "type": "string",
			   "index": "analyzed",
			   "store": "yes",
			   "search_analyzer": "simple_nGram_analyzer",
			   "analyzer": "simple_nGram_analyzer"
			}
		 }
	  }
   }
}
POST test/doc
{
   "description": "Mark Twain"
}
GET test/_search
{
   "query": {
	  "match": {
		 "description": "rk tw"
	  }
   }
}
GET test/_search
{
   "query": {
	  "term": {
		 "description": "rk tw"
	  }
   }
}
```

---

<div class="post-metadata">

**Author:** ![uncleBens](https://avatars.discourse-cdn.com/v4/letter/u/a9a28c/32.png) [@uncleBens](https://discuss.elastic.co/u/uncleBens)\
**Post date:** [September 9, 2016, 7:19pm UTC](https://discuss.elastic.co/t/problem-with-mapping-and-matchquery/59975/3 "2016-09-09T19:19:00Z")

</div>

It turns out that index was not updated for some reason and then it worked better but still something was wrong.

I am sorry for the inconvenience. Moreover I must used other search\_analyzer as opposed to analyzer. Analyzer is ngram and search\_analyzer is keyword.

Having ngram in both search\_analyzer and analyzer I searched "rk tw" and it returned too many results, like Tom Twain or something like his. I guess it didn't keep the sequence in search string and instead search words with "rk tw" substring it search words having "rk" or "tw" inside.

Today I know that I can setup mapping which would index the same field in document different manner and different names and it is possible to boost fields so maybe I will play with it a bit more.

---

<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:21pm UTC](https://discuss.elastic.co/t/problem-with-mapping-and-matchquery/59975/4 "2017-07-05T22:21:25Z")

</div>


