# Process string when storing in index

**URL:** <https://discuss.elastic.co/t/process-string-when-storing-in-index/7037>\
**Category:** Elasticsearch\
**Created:** [March 17, 2012, 1:06pm UTC](https://discuss.elastic.co/t/process-string-when-storing-in-index/7037 "2012-03-17T13:06:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jippe\_Holwerda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jippe_holwerda/32/2957_2.png) [@Jippe\_Holwerda](https://discuss.elastic.co/u/Jippe_Holwerda)\
**Post date:** [March 17, 2012, 1:06pm UTC](https://discuss.elastic.co/t/process-string-when-storing-in-index/7037/1 "2012-03-17T13:06:26Z")

</div>

Hi all,

I'm using Elasticsearch as a backend for a website, where documents coming  
from a Content Management System are stored in Elasticsearch.

Now I'm looking into a mapping scheme from documents to friendly URLs and  
back. For instance, a document having title 'G3PH industrial high-power  
solid state relay' should map to  
'g3ph-industrial-high-power-solid-state-relay'. That name can then be used  
in a URL. Using that URL, the correct document should be fetched from  
Elasticsearch and shown on a page.

What would be the best way to implement this?

One solution would be to transform the title field and store it in a  
multi\_field upon storing a document in the index.  
Should I create a custom analyzer for this? Use a scripting field?

Cheers,  
Jippe Holwerda

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 20, 2012, 9:49am UTC](https://discuss.elastic.co/t/process-string-when-storing-in-index/7037/2 "2012-03-20T09:49:38Z")

</div>

You mean you want to store the field differently? Index it differently? Or,  
perhaps, fetch is differently when executing a search?

On Sat, Mar 17, 2012 at 3:06 PM, Jippe Holwerda [mail@jippeholwerda.nl](mailto:mail@jippeholwerda.nl)wrote:

> Hi all,
> 
> I'm using Elasticsearch as a backend for a website, where documents coming  
> from a Content Management System are stored in Elasticsearch.
> 
> Now I'm looking into a mapping scheme from documents to friendly URLs and  
> back. For instance, a document having title 'G3PH industrial high-power  
> solid state relay' should map to  
> 'g3ph-industrial-high-power-solid-state-relay'. That name can then be used  
> in a URL. Using that URL, the correct document should be fetched from  
> Elasticsearch and shown on a page.
> 
> What would be the best way to implement this?
> 
> One solution would be to transform the title field and store it in a  
> multi\_field upon storing a document in the index.  
> Should I create a custom analyzer for this? Use a scripting field?
> 
> Cheers,  
> Jippe Holwerda

---

<div class="post-metadata">

**Author:** ![Jippe\_Holwerda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jippe_holwerda/32/2957_2.png) [@Jippe\_Holwerda](https://discuss.elastic.co/u/Jippe_Holwerda)\
**Post date:** [March 20, 2012, 10:23am UTC](https://discuss.elastic.co/t/process-string-when-storing-in-index/7037/3 "2012-03-20T10:23:09Z")

</div>

Well, I want to be able to search on the friendly URL, so it definitely  
should be indexed. That's why I think fetching it differently when  
executing a search is too late.

My ideal solution would be to be able to specify a multi\_field in the  
mapping where I have 3 subfields: one where the title is analyzed, one  
where it is not analyzed and one where I can specify a custom mapping  
function (Javascript?) that takes the title as input.

The alternative would be to simply make sure I have the necessary  
information in the JSON available and not analyze it. But I was wondering  
whether I could solve it in Elasticsearch as well.

On Tuesday, March 20, 2012 10:49:38 AM UTC+1, kimchy wrote:

> You mean you want to store the field differently? Index it differently?  
> Or, perhaps, fetch is differently when executing a search?
> 
> Hi all,
> 
> > I'm using Elasticsearch as a backend for a website, where documents  
> > coming from a Content Management System are stored in Elasticsearch.
> > 
> > Now I'm looking into a mapping scheme from documents to friendly URLs and  
> > back. For instance, a document having title 'G3PH industrial high-power  
> > solid state relay' should map to  
> > 'g3ph-industrial-high-power-solid-state-relay'. That name can then be used  
> > in a URL. Using that URL, the correct document should be fetched from  
> > Elasticsearch and shown on a page.
> > 
> > What would be the best way to implement this?
> > 
> > One solution would be to transform the title field and store it in a  
> > multi\_field upon storing a document in the index.  
> > Should I create a custom analyzer for this? Use a scripting field?
> > 
> > Cheers,  
> > Jippe Holwerda

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 20, 2012, 11:01am UTC](https://discuss.elastic.co/t/process-string-when-storing-in-index/7037/4 "2012-03-20T11:01:31Z")

</div>

There isn't an option to define a field that indexes the result of a  
script. You could write a plugin that has a custom type, but the simplest  
option is to preprocess the json before indexing.

On Tue, Mar 20, 2012 at 12:23 PM, Jippe Holwerda [mail@jippeholwerda.nl](mailto:mail@jippeholwerda.nl)wrote:

> Well, I want to be able to search on the friendly URL, so it definitely  
> should be indexed. That's why I think fetching it differently when  
> executing a search is too late.
> 
> My ideal solution would be to be able to specify a multi\_field in the  
> mapping where I have 3 subfields: one where the title is analyzed, one  
> where it is not analyzed and one where I can specify a custom mapping  
> function (Javascript?) that takes the title as input.
> 
> The alternative would be to simply make sure I have the necessary  
> information in the JSON available and not analyze it. But I was wondering  
> whether I could solve it in Elasticsearch as well.
> 
> On Tuesday, March 20, 2012 10:49:38 AM UTC+1, kimchy wrote:
> 
> > You mean you want to store the field differently? Index it differently?  
> > Or, perhaps, fetch is differently when executing a search?
> > 
> > Hi all,
> > 
> > > I'm using Elasticsearch as a backend for a website, where documents  
> > > coming from a Content Management System are stored in Elasticsearch.
> > > 
> > > Now I'm looking into a mapping scheme from documents to friendly URLs  
> > > and back. For instance, a document having title 'G3PH industrial high-power  
> > > solid state relay' should map to 'g3ph-industrial-high-power-\*\*solid-state-relay'.  
> > > That name can then be used in a URL. Using that URL, the correct document  
> > > should be fetched from Elasticsearch and shown on a page.
> > > 
> > > What would be the best way to implement this?
> > > 
> > > One solution would be to transform the title field and store it in a  
> > > multi\_field upon storing a document in the index.  
> > > Should I create a custom analyzer for this? Use a scripting field?
> > > 
> > > Cheers,  
> > > Jippe Holwerda

---

<div class="post-metadata">

**Author:** ![Jippe\_Holwerda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jippe_holwerda/32/2957_2.png) [@Jippe\_Holwerda](https://discuss.elastic.co/u/Jippe_Holwerda)\
**Post date:** [March 20, 2012, 11:10am UTC](https://discuss.elastic.co/t/process-string-when-storing-in-index/7037/5 "2012-03-20T11:10:03Z")

</div>

Ok, that's clear. Thanks for your answer.

On Mar 20, 2012, at 12:01 , Shay Banon wrote:

> There isn't an option to define a field that indexes the result of a script. You could write a plugin that has a custom type, but the simplest option is to preprocess the json before indexing.
> 
> On Tue, Mar 20, 2012 at 12:23 PM, Jippe Holwerda [mail@jippeholwerda.nl](mailto:mail@jippeholwerda.nl) wrote:  
> Well, I want to be able to search on the friendly URL, so it definitely should be indexed. That's why I think fetching it differently when executing a search is too late.
> 
> My ideal solution would be to be able to specify a multi\_field in the mapping where I have 3 subfields: one where the title is analyzed, one where it is not analyzed and one where I can specify a custom mapping function (Javascript?) that takes the title as input.
> 
> The alternative would be to simply make sure I have the necessary information in the JSON available and not analyze it. But I was wondering whether I could solve it in Elasticsearch as well.
> 
> On Tuesday, March 20, 2012 10:49:38 AM UTC+1, kimchy wrote:  
> You mean you want to store the field differently? Index it differently? Or, perhaps, fetch is differently when executing a search?
> 
> Hi all,
> 
> I'm using Elasticsearch as a backend for a website, where documents coming from a Content Management System are stored in Elasticsearch.
> 
> Now I'm looking into a mapping scheme from documents to friendly URLs and back. For instance, a document having title 'G3PH industrial high-power solid state relay' should map to 'g3ph-industrial-high-power-solid-state-relay'. That name can then be used in a URL. Using that URL, the correct document should be fetched from Elasticsearch and shown on a page.
> 
> What would be the best way to implement this?
> 
> One solution would be to transform the title field and store it in a multi\_field upon storing a document in the index.  
> Should I create a custom analyzer for this? Use a scripting field?
> 
> Cheers,  
> Jippe Holwerda

---

<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:35am UTC](https://discuss.elastic.co/t/process-string-when-storing-in-index/7037/6 "2017-07-06T03:35:28Z")

</div>


