# Field norm calculation on ElasticSearch array fields

**URL:** <https://discuss.elastic.co/t/field-norm-calculation-on-elasticsearch-array-fields/18653>\
**Category:** Elasticsearch\
**Created:** [July 14, 2014, 5:04pm UTC](https://discuss.elastic.co/t/field-norm-calculation-on-elasticsearch-array-fields/18653 "2014-07-14T17:04:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor\_Girotto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/victor_girotto/32/1407_2.png) [@Victor\_Girotto](https://discuss.elastic.co/u/Victor_Girotto)\
**Post date:** [July 14, 2014, 5:04pm UTC](https://discuss.elastic.co/t/field-norm-calculation-on-elasticsearch-array-fields/18653/1 "2014-07-14T17:04:56Z")

</div>

(Originally posted on Stack Overflow  
[http://stackoverflow.com/questions/24708104/field-norm-calculation-on-elasticsearch-array-fields](http://stackoverflow.com/questions/24708104/field-norm-calculation-on-elasticsearch-array-fields)  
)

Here's the mapping for one of the fields in my index:

"resourceId": {  
"type": "string",  
"index\_analyzer": "partial\_match",  
"search\_analyzer": "lowercase",  
"include\_in\_all": true  
}

Here are the custom analyzers used in the index:

"analysis": {  
"filter": {  
"partial\_match\_filter": {  
"type": "ngram",  
"min\_gram": 1,  
"max\_gram": 50  
}  
},  
"analyzer": {  
"partial\_match": {  
"type": "custom",  
"tokenizer": "whitespace",  
"filter": [  
"lowercase",  
"partial\_match\_filter"  
]  
},  
"lowercase": {  
"type": "custom",  
"tokenizer": "whitespace",  
"filter": [  
"lowercase"  
]  
}  
}  
}

This field will contain an array of strings, which are the multiple IDs  
that a resource can have (it can have multiple IDs due to different systems  
calling each resource by a different id).

Now let's suppose that _resource #1_ has has three IDs:

resourceId: [3]  
0: "ID:MATCH"  
1: "MATCH"  
2: "ID:ALT"

And that _resource #2_ has only one ID:

resourceId: [1]  
0: "ID:MATCHFIVE"

And let's suppose that we run this query against my index:

{  
"from": 0,  
"size": 30,  
"query": {  
"query\_string": {  
"query": "resourceId:ID\:MATCH"  
}  
}  
}

What I'd like is for resource #1 to show up first, since its array contains  
an exact match. _However, resource #2 is the one coming on top_;

When I used the _explain_ parameter on the query request, I saw that the  
_tf_ and _idf_ scores where the same for both resources. _However,  
the norm score was lower for resource #1_.

My theory is that since resource #1 has three items in the array (which I  
assume are concatenated together during indexing), the field is considered  
larger, and thus the norm value is decreased. When it comes to resource #2,  
it has only one item (and it's shorter than the concatenation of the other  
array), so the norm is higher, bumping the resource to the top.

My question, therefore, is: _when calculating the score, is it possible for  
the norm calculation to only consider the size of the item that matched in  
the array?_

For example: the search for "ID:MATCH" would find the exact match on  
resource #1 on resourceId[0]. At this point, all other items in the array  
would be put aside and the _norm_ would be calculated based on that single  
item (resourceId[0]), showing a perfect match. As for resource #2, the norm  
would be lower, since the resourceId field would be larger.

If this isn't possible, would there be workarounds to get the exact match  
to the top? Or maybe I'm completely off on my theory?

In case it's useful, I'm using version 1.1.1.

I'll be glad to provide any more information you may need.

Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/967828ea-9004-45f3-83ba-adad29948d5c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/967828ea-9004-45f3-83ba-adad29948d5c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:15am UTC](https://discuss.elastic.co/t/field-norm-calculation-on-elasticsearch-array-fields/18653/2 "2017-07-06T01:15:59Z")

</div>


