# Elastic search : EdgeGram, prefix, suffix

**URL:** <https://discuss.elastic.co/t/elastic-search-edgegram-prefix-suffix/10648>\
**Category:** Elasticsearch\
**Created:** [February 7, 2013, 11:25am UTC](https://discuss.elastic.co/t/elastic-search-edgegram-prefix-suffix/10648 "2013-02-07T11:25:32Z")\
**Posts on this page:** 3\
**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:25am UTC](https://discuss.elastic.co/t/elastic-search-edgegram-prefix-suffix/10648/1 "2013-02-07T11:25:32Z")

</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\* COR\*PORATION “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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 8, 2013, 10:43am UTC](https://discuss.elastic.co/t/elastic-search-edgegram-prefix-suffix/10648/2 "2013-02-08T10:43:22Z")

</div>

I think i answered yesterday. Use ngram, not EdgeNGram.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 7 févr. 2013 à 12:25, Mohit Kumar Yadav [mohit.kumar.ngi@gmail.com](mailto:mohit.kumar.ngi@gmail.com) a écrit :

> 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 Elasticsearch 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).

--  
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-edgegram-prefix-suffix/10648/3 "2017-07-06T02:52:27Z")

</div>


