Problem with mapping and matchQuery

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();

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"
	  }
   }
}

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.