# \[ANN\] new analysis plugin:elasticsearch-analysis-string2int

**URL:** <https://discuss.elastic.co/t/ann-new-analysis-plugin-elasticsearch-analysis-string2int/9559>\
**Category:** Elasticsearch\
**Created:** [November 5, 2012, 1:18pm UTC](https://discuss.elastic.co/t/ann-new-analysis-plugin-elasticsearch-analysis-string2int/9559 "2012-11-05T13:18:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![medcl\_net](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@medcl\_net](https://discuss.elastic.co/u/medcl_net)\
**Post date:** [November 5, 2012, 1:18pm UTC](https://discuss.elastic.co/t/ann-new-analysis-plugin-elasticsearch-analysis-string2int/9559/1 "2012-11-05T13:18:17Z")

</div>

Hi,folks,  
i just released a new analysis plugin for elasticsearch,the repo link is here:

> **[medcl/elasticsearch-analysis-string2int](https://github.com/medcl/elasticsearch-analysis-string2int)**
>
> elasticsearch-analysis-string2int - string2integer analysis for elasticsearch,save your memory and reduce the size of your index,the size of the filedcache can be reduced from giga to mega,and also...

this plugin is used for saving your memory and reduce the size of your  
index. sometimes there are some entities in our index,for  
example,people's name,the title of you position,and so on, generally  
we set these fields to not\_analyzed and hope to use them together, and  
they often slightly change ,but if you wanna do faceting over these  
fields, you should be very carefully,because the memory usage is a  
headache,especially it contains a lot of of terms, but if you can  
convert these long string entities into numbers, the memory usage will  
be a little smaller,and make the impossible thing to be possible.

the plugin use redis to store the mapping of your entity and the  
number. the number is assigned by auto\_increment style,and in order to  
speedup the indexing,there is a local cache in memory.

hey,wait a minute,  
how to use this plugin?

ok,come with me~

1.step one,add a custom analysis type in the elasticsearch.yml

index:  
analysis:  
analyzer:  
string2int:  
type: org.elasticsearch.index.analysis.String2IntAnalyzerProvider  
redis\_server: "127.0.0.1"  
redis\_port: 6379  
redis\_key: "index1\_type1\_name1"

the redis\_key is like a catalog of your entities

1. step two,create a index,and create a type ,and make sure the  
field's index\_analyzer is string2int,the analyzer we just defined..

curl -XPOST [http://localhost:9200/index/string2int/\_mapping](http://localhost:9200/index/string2int/_mapping) -d'  
{  
"string2int": {  
"\_meta": {  
"author": "medcl"  
},  
"\_all": {  
"analyzer": "ik"  
},  
"\_source": {  
"enabled": false  
},  
"properties": {  
"author": {  
"type": "string",  
"index\_analyzer": "string2int",  
"search\_analyzer": "keyword",  
"include\_in\_all": false,  
"store":true  
}  
}  
}  
}'

3.step 3,as the filed is named "author",so let's index some people

curl -XPOST [http://localhost:9200/index/string2int/1](http://localhost:9200/index/string2int/1) -d'  
{"author":"medcl"}'

curl -XPOST [http://localhost:9200/index/string2int/2](http://localhost:9200/index/string2int/2) -d'  
{"author":"michael jackson"}'

...

4.do faceting now

curl -XPOST [http://localhost:9200/index/string2int/\_search](http://localhost:9200/index/string2int/_search) -d'  
{  
"query": {  
"query\_string": {  
"query": "\*"  
}  
},  
"facets": {  
"author": {  
"terms": {  
"field": "author"  
}  
}  
}  
}'

response:

{"took":9,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max\_score":1.0,"hits":[{"\_index":"index","\_type":"string2int","\_id":"1","\_score":1.0},{"\_index":"index","\_type":"string2int","\_id":"2","\_score":1.0},{"\_index":"index","\_type":"string2int","\_id":"3","\_score":1.0}]},"facets":{"author":{"\_type":"terms","missing":0,"total":3,"other":0,"terms":[{"term":"6","count":2},{"term":"7","count":1}]}}}

the next step is to replace the everything back. and you can also  
change the field's mapping,by set store to true,to get them back  
directly.

you can ref the RTF Project  
([https://github.com/medcl/elasticsearch-rtf](https://github.com/medcl/elasticsearch-rtf)) to see the detail  
tutorial.

appreciate any feedback and comments.

//Medcl

--

---

<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, 3:06am UTC](https://discuss.elastic.co/t/ann-new-analysis-plugin-elasticsearch-analysis-string2int/9559/2 "2017-07-06T03:06:12Z")

</div>

Closed on July 6, 2017, 3:06am UTC


