AS I know that We can control the size of the highlighted fragment. But I want to control the size of the specific field result.
ex)
I can control size highlighted by using fragment_size, number_of_fragments.
highlight: {
"CONTEXT": [
"I am leaving today.I want to be a part of it New York, New York These <b>vagabond</b> shoes They are"
]
}
But I want to get result as like this;
fields: {
"CONTEXT": [
"I am leaving today.I want to be a part of it New York, New York These vagabond shoes They are longing to stray Right through the very heart of it New York, New York ..."
],
"TITLE": [
"new york new york"
]
},
Because, Sometimes This context field is too long to display result Web Page. So, I want to control size CONTEXT field result.
You can do something like the following, but I'd suggest if you can to do this on the client side.
{
"settings": {
"analysis": {
"filter": {
"truncate_filter": {
"type": "truncate",
"length": 20
}
},
"analyzer": {
"my_truncate_analyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"truncate_filter"
]
}
}
}
},
"mappings": {
"test": {
"properties": {
"context": {
"type": "string",
"fields": {
"truncated": {
"type": "string",
"analyzer": "my_truncate_analyzer"
}
}
}
}
}
}
}
And in your query you'd need to add a fielddata_fields to see the truncated field:
{
"query": {
...
},
"fielddata_fields": ["context.truncated"]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With