I have hypen separated in one column and i want to use that column in elastic search. Mapping created with type. Need to escape the hypen and get the whole value

Below is mapping:
"TestID" : {
"type" : "text",
"fielddata" : true

Example value of ID is "12333-1arerd-2333d-rrrrrwwqq"

In the scripted field of the Index pattern i have given the below Script:
if (doc['TestID'] == null || doc['TestID'].isEmpty())
{
return "";
}
String res = doc['TestID'][0];
return res;

After created index and Inserted data, i could get only the part of the ID.

"TestID": [
"2333d"]

How to escape this hypen and pass the whole id value. Due to token i am getting it in terms.

Hi @Sreenath_G Welcome to the community.

Have you thought about just creating a multi-type field

"TestID" : {
  "type" : "text",
  "fields" : {
    "keyword" : {
      "type" : "keyword",
      "ignore_above" : 256
    }
  }
}

The to get the whole field you would just access the TestID.keyword field which would have the whole string untokenized, that way you could do text search and still have the whole unaltered string.

Thanks for your reply and time.
Could you please let me know if there is any possiblity for getting the untokenzied value of the ID without changing the mapping from Text to Keyword.
As mentioned earlier, below is the script which i have tried in the Scriptted field:

if (doc['TestID'] == null || doc['TestID'].isEmpty()) {
return "";
}
String res = doc['TestID'][0];
return res;

I am not a scripting expert but the original string should still be in the _source I would look how to access that.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.