0

I am new to Elasticsearch and I want to know if we have a way to change the value of the alias index ? I will give you examples;

For example we have a index that holds the credit card numbers;

4444-444-777 .... and so on,

Then I have a alias to that index, lets say alias1,

What I want to do is, once I call alias1, the user will automatically see;

xxxx-xxx-777 instead of 4444-444-777.

Can you please give me some ideas how to do it ?

Kromster
  • 7,181
  • 7
  • 63
  • 111
mehmetozer
  • 848
  • 6
  • 14
  • 30

1 Answers1

1

I'm afraid this is not possible with aliases. Aliases have functionality to filter the query, but this is just an inclusion / exclusion filter. For example, alias1 could be a filtered alias that only allows the search query to see user1 documents.

Aliases do not have any capability to actually modify or manipulate data.

There are some options, but they all have trade-offs.

Script Fields

You can use Script Fields to provide a "virtual" field. Essentially, you run a script which loads some field, then performs whatever manipulation you need (e.g. 4444-444-777 -> xxxx-xxx-777). This is then returned to you as an extra field in the search results. The caveat is that the original data is still visible in the original _source, so your app will need to make sure that isn't exposed.

Transform

If you don't ever want the original data to be returned, you can perform a Transform which will physically alter the _source document before it is indexed. This means that the data you get back from the search results will be pre-manipulated...but you will never be able to access the original data (because it has been transformed).

Your application code

It may be best to just perform this filtering in your application code. Simpler, easier to change, not doing anything fundamentally different from what ES would have to do anyway.

Zach
  • 9,591
  • 1
  • 38
  • 33
  • Hello, thanks for your answer actually I am trying to use script fields but there is something that i can not understand, can you please look at it ? http://stackoverflow.com/questions/29105351/can-not-get-result-of-script-fields-in-elasticsearch – mehmetozer Mar 17 '15 at 17:19