# Elastic search Query Related to EdgeGram

**URL:** <https://discuss.elastic.co/t/elastic-search-query-related-to-edgegram/10649>\
**Category:** Elasticsearch\
**Created:** [February 7, 2013, 11:37am UTC](https://discuss.elastic.co/t/elastic-search-query-related-to-edgegram/10649 "2013-02-07T11:37:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohit\_Kumar](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@mohit\_Kumar](https://discuss.elastic.co/u/mohit_Kumar)\
**Post date:** [February 7, 2013, 11:37am UTC](https://discuss.elastic.co/t/elastic-search-query-related-to-edgegram/10649/1 "2013-02-07T11:37:38Z")

</div>

How one can search a word through its middle or last letters. For example  
CORPORATION is a words and I am able to search CORPORATION with its  
initials like COR, CO, C etc by using EdgeGram and prefix filter. but I am  
not able to search it with last letters or middle letters of CORPORATION  
that is POR or RATI or ION. is elastic search support this features? if yes  
then please help me how can I resolve this issue.

EdgeGram Mapping and Setting:

curl -X PUT "[http://192.168.1.15:9200/catalog](http://192.168.1.15:9200/catalog)" -d '{  
"mappings" : {  
"product" : {  
"properties" : {  
"title" : {  
"type" : "string",  
"search\_analyzer" : "str\_search\_analyzer",  
"index\_analyzer" : "str\_index\_analyzer"  
}  
}  
}  
},

"settings" : {  
"analysis" : {  
"analyzer" : {  
"str\_search\_analyzer" : {  
"tokenizer" : "keyword",  
"filter" : ["lowercase"]  
},

```
    "str_index_analyzer" : {
      "tokenizer" : "keyword",
      "filter" : ["lowercase", "substring"]
    }
  },

  "filter" : {
    "substring" : {
      "type" : "edgeNGram",
      "min_gram" : 1,
      "max_gram" : 20
    }
  }
}

```

}  
}'

Inserting Value :

curl -X PUT "[http://192.168.1.15:9200/catalog/product/1](http://192.168.1.15:9200/catalog/product/1)" -d '{  
"title" : "CORPORATION"  
}'

Search Query initials of CORPORATION “COR":

curl "[http://192.168.1.15:9200/catalog/product/\_search?pretty=1](http://192.168.1.15:9200/catalog/product/_search?pretty=1)" -d '{  
"query" : {  
"text" : {  
"title" : "COR"  
}  
}  
}'

Output:

{  
"took" : 98,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 0.076713204,  
"hits" : [ {  
"\_index" : "catalog",  
"\_type" : "product",  
"\_id" : "1",  
"\_score" : 0.076713204, "\_source" : {  
"title" : "CORPORATION"  
}  
} ]  
}  
}

Second query : middle letters of CORPORATION "POR"

curl "[http://192.168.1.15:9200/catalog/product/\_search?pretty=1](http://192.168.1.15:9200/catalog/product/_search?pretty=1)" -d '{  
"query" : {  
"text" : {  
"title" : "POR"  
}  
}  
}'

output:

{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

Third query : last letters of CORPORATION "TION"

curl "[http://192.168.1.15:9200/catalog/product/\_search?pretty=1](http://192.168.1.15:9200/catalog/product/_search?pretty=1)" -d '{  
"query" : {  
"text" : {  
"title" : "TION"  
}  
}  
}'  
output:  
{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:52am UTC](https://discuss.elastic.co/t/elastic-search-query-related-to-edgegram/10649/2 "2017-07-06T02:52:34Z")

</div>


