Andrey
Andrey

Reputation: 925

ElasticSearch Format field on document creation

I have a mapping with 1 field:

"message" : {
    "type" : "text"
}

I insert a new document:

"message" : " 123 "

Is it possible to change field text (trim) via ES functionality?
The purpose is to create a standard for field "message".
Clarification: Not to filter text for reverse index, but for original text.

Required output should be:

{
     "message" : "123"   
}

Upvotes: 0

Views: 77

Answers (1)

Val
Val

Reputation: 217514

Yes, you can achieve that using an ingest pipeline with a trim processor.

First define the ingest pipeline:

PUT _ingest/pipeline/my-pipeline
{
  "description": "My ingest pipeline",
  "processors": [
    {
      "trim": {
        "field": "message"
      }
    }
  ]
}

Then simply specify the pipeline to use when indexing your documents:

PUT my-index/doc/1?pipeline=my-pipeline
{
  "message": " 123 "
}

Then you can see that the leading and trailing whitespaces have been removed

GET my-index/doc/1
=>
{
  "message": "123"
}

Upvotes: 1

Related Questions