This is my mapping, where I override score script with single property doc.length
:
{
"mappings": {
"some_info": {
"_all": {
"enabled": "false"
},
"properties": {
"some_text_field": {
"type": "text",
"index": "false",
"fields": {
"ngram": {
"type": "text",
"analyzer": "custom_nGram_analyzer",
"similarity": "my_similarity"
}
}
}
}
}
},
"settings": {
"analysis": {
"analyzer": {
"custom_nGram_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding",
"custom_nGram_filter"
]
}
},
"filter": {
"custom_nGram_filter": {
"type": "ngram",
"token_chars": [],
"min_gram": 3,
"max_gram": 16
}
},
"normalizer": {
"custom_lowercase_normalizer": {
"type": "custom",
"filter": [
"lowercase"
]
}
}
},
"similarity": {
"my_similarity": {
"type": "scripted",
"script": {
"source": "return doc.length;"
}
}
}
}
}
data: POST: /some_index/some_info
{
"some_text_field": "Lorem Ipsum is simply ...."
}
when I perform query: GET /some_index/_search?q=Lorem
I get score: 76.0
but when I do: GET /some_index/_search?q=Lorem Ipsum
I get score: 152.0
_explaination shows something like this:
"_explanation": {
"value": 152.0,
"description": "max of:",
"details": [
{
"value": 152.0,
"description": "sum of:",
"details": [
{
"value": 76.0,
"description": "weight(Synonym(some_text_field.ngram:lor some_text_field.ngram:lore some_text_field.ngram:lorem some_text_field.ngram:ore some_text_field.ngram:orem some_text_field.ngram:rem) in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 76.0,
"description": "score from ScriptedSimilarity(weightScript=[null], script=[Script{type=inline, lang='painless', idOrCode='return doc.length;', options={}, params={}}]) computed from:",
"details": [
...
{
"value": 76.0,
"description": "doc.length",
"details": []
}
]
}
]
},
{
"value": 76.0,
"description": "weight(Synonym(some_text_field.ngram:ips some_text_field.ngram:ipsu some_text_field.ngram:ipsum some_text_field.ngram:psu some_text_field.ngram:psum some_text_field.ngram:sum) in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 76.0,
"description": "score from ScriptedSimilarity(weightScript=[null], script=[Script{type=inline, lang='painless', idOrCode='return doc.length;', options={}, params={}}]) computed from:",
"details": [
...
{
"value": 76.0,
"description": "doc.length",
"details": []
}
]
}
]
}
]
}
]
Is there any way to get doc.length without summing it?