Created
February 9, 2017 15:41
-
-
Save inqueue/107da120e45c9e97aac9e9bec7abcc70 to your computer and use it in GitHub Desktop.
Elasticsearch: truncate a field using a script processor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT _ingest/pipeline/truncate-field | |
{ | |
"description": "Use the Script processor to truncate a field to 10 characters", | |
"processors": [ | |
{ | |
"script": { | |
"inline": "ctx.foo = ctx.foo.substring(0, (int) Math.min(10, ctx.foo.length()))" | |
} | |
} | |
] | |
} | |
# Simulate request | |
POST _ingest/pipeline/truncate-field/_simulate | |
{ | |
"docs" : [ | |
{ | |
"_source": { | |
"foo": "0123456789 this will be truncated" | |
} | |
}, | |
{ | |
"_source": { | |
"foo": "98765" | |
} | |
}, | |
{ | |
"_source": { | |
"foo": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
} | |
} | |
] | |
} | |
# Simulate response | |
{ | |
"docs": [ | |
{ | |
"doc": { | |
"_type": "_type", | |
"_id": "_id", | |
"_index": "_index", | |
"_source": { | |
"foo": "0123456789" | |
}, | |
"_ingest": { | |
"timestamp": "2017-02-09T15:31:36.905Z" | |
} | |
} | |
}, | |
{ | |
"doc": { | |
"_type": "_type", | |
"_id": "_id", | |
"_index": "_index", | |
"_source": { | |
"foo": "98765" | |
}, | |
"_ingest": { | |
"timestamp": "2017-02-09T15:31:36.905Z" | |
} | |
} | |
}, | |
{ | |
"doc": { | |
"_type": "_type", | |
"_id": "_id", | |
"_index": "_index", | |
"_source": { | |
"foo": "ABCDEFGHIJ" | |
}, | |
"_ingest": { | |
"timestamp": "2017-02-09T15:31:36.905Z" | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment