0

I'm trying to change few fields strings using javascript.

For example take only the last part of the URL taken from mongo through the river so in elasticsearch I'll have only the end of it.

When creating the index (using curl) I added under "options" the following script:

"script": "ctx.document.shorturl = ctx.document.url.substr(-4);delete ctx.document.url;

I tried some manipulations such as adding \"...\" or use ctx['doc']['url'] and others but nothing seems to work.

I always get only url field with the full url (shorturl is not created at all).

Can anyone suggest what is the right syntax to make it work?

Another thing I need to do is combine to fields - lat & long, to one "location" field in order to use it in Kibana, can anyone suggest the right script for that? (create new field called "location" which contain both field "lat" & "long" with comma between them). Thanks.

Ethaan
  • 11,291
  • 5
  • 35
  • 45
Guy Rom
  • 1
  • 1

1 Answers1

0

You did substring(-4), hence it will return the whole string. You should use substring(4) instead:

ctx.document.shorturl = ctx.document.url.substr(4);delete ctx.document.url;
nalply
  • 26,770
  • 15
  • 78
  • 101
zam
  • 1