# Document size and score during search

**URL:** <https://discuss.elastic.co/t/document-size-and-score-during-search/15431>\
**Category:** Elasticsearch\
**Created:** [January 27, 2014, 11:02am UTC](https://discuss.elastic.co/t/document-size-and-score-during-search/15431 "2014-01-27T11:02:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hiro\_Gangwani](https://avatars.discourse-cdn.com/v4/letter/h/9fc29f/32.png) [@Hiro\_Gangwani](https://discuss.elastic.co/u/Hiro_Gangwani)\
**Post date:** [January 27, 2014, 11:02am UTC](https://discuss.elastic.co/t/document-size-and-score-during-search/15431/1 "2014-01-27T11:02:24Z")

</div>

Dear Sir,

We are indexing the document content and executing text based search from  
document content. Is there way to disable lucene's preference to score  
shorter documents higher?

Consider following example

1. we have 2 documents A and B
2. We execute search based upon text Java
3. A document has 10 matching words while document B has 7 words. But size  
of document B is smaller than document A.
4. During search operation document B is assigned higher score because its  
size is smaller than document A( Though A has higher count of words Java)

In one of forums we learnt that using omit\_norms we can ignore the size of  
document while indexing. We tried this approach and still not getting the  
desired results.

we are using Java API to create the indexes using XContentBuilder. please  
find the code below

-- Creating index  
XContentBuilder map = XContentFactory.jsonBuilder().startObject()  
.startObject(idxType)  
.startObject("properties")  
.startObject("file")  
.field("type", "attachment")  
._field("omit\_norm","true")_  
.startObject("fields")  
.startObject("refid")  
.field("store", "yes")  
.endObject()  
.startObject("name")  
.field("store", "yes")  
.endObject()  
.startObject("itexp")  
.field("store", "yes")  
.endObject()  
.startObject("totalexp")  
.field("store", "yes")  
.endObject()  
.endObject()  
.endObject()  
.endObject()  
.endObject();  
CreateIndexResponse lResponse =  
client.admin().indices().prepareCreate(idxName)  
.addMapping("attachment", map).execute().actionGet();

--- Indexing document

```
XContentBuilder source = XContentFactory.jsonBuilder().startObject()
.field("file", data64)
.field("refid", "2")
.field("name", "Maya")     
.field("totalexp",11.0);

```

Please let me know if above code is correct.We are not getting desired  
results even after applying the omit\_norms parameter.

Thanks in advance

Hiro Gangwani

--  
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/b707663b-7b7b-48cd-ab96-4490a0171ec1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b707663b-7b7b-48cd-ab96-4490a0171ec1%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 28, 2014, 8:59am UTC](https://discuss.elastic.co/t/document-size-and-score-during-search/15431/2 "2014-01-28T08:59:14Z")

</div>

Hey,

iirc you cannot set omit\_norms in the attachment type itself (as that type  
consist of several sub fields). You need to set it for the "file", like  
this (untested, on the top of my head)

XContentBuilder map = XContentFactory.jsonBuilder().startObject()  
.startObject(idxType)  
.startObject("properties")  
.startObject("file")  
.field("type", "attachment")  
.startObject("fields")  
.startObject("file")  
.field("omit\_norms",true)  
.endObject()

Also, note that it omit\_norms and not omit\_norm. In addition I dont know,  
what the refid, itexp and totalexp fields are used for inside of the  
attachment, see the documentation for supported fields

> **[GitHub - elastic/elasticsearch-mapper-attachments: Mapper Attachments Type...](https://github.com/elastic/elasticsearch-mapper-attachments)**
>
> Mapper Attachments Type plugin for Elasticsearch. Contribute to elastic/elasticsearch-mapper-attachments development by creating an account on GitHub.

Maybe it is something internal I am not aware of.

--Alex

On Mon, Jan 27, 2014 at 12:02 PM, Hiro Gangwani [hiro.gangwani@gmail.com](mailto:hiro.gangwani@gmail.com)wrote:

> Dear Sir,
> 
> We are indexing the document content and executing text based search from  
> document content. Is there way to disable lucene's preference to score  
> shorter documents higher?
> 
> Consider following example
> 
> 1. we have 2 documents A and B
> 2. We execute search based upon text Java
> 3. A document has 10 matching words while document B has 7 words. But size  
> of document B is smaller than document A.
> 4. During search operation document B is assigned higher score because its  
> size is smaller than document A( Though A has higher count of words Java)
> 
> In one of forums we learnt that using omit\_norms we can ignore the size of  
> document while indexing. We tried this approach and still not getting the  
> desired results.
> 
> we are using Java API to create the indexes using XContentBuilder. please  
> find the code below
> 
> -- Creating index  
> XContentBuilder map = XContentFactory.jsonBuilder().startObject()  
> .startObject(idxType)  
> .startObject("properties")  
> .startObject("file")  
> .field("type", "attachment")  
> ._field("omit\_norm","true")_  
> .startObject("fields")  
> .startObject("refid")  
> .field("store", "yes")  
> .endObject()  
> .startObject("name")  
> .field("store", "yes")  
> .endObject()  
> .startObject("itexp")  
> .field("store", "yes")  
> .endObject()  
> .startObject("totalexp")  
> .field("store", "yes")  
> .endObject()  
> .endObject()  
> .endObject()  
> .endObject()  
> .endObject();  
> CreateIndexResponse lResponse =  
> client.admin().indices().prepareCreate(idxName)  
> .addMapping("attachment", map).execute().actionGet();
> 
> --- Indexing document
> 
> ```
> XContentBuilder source = XContentFactory.jsonBuilder().startObject()
> .field("file", data64)
> .field("refid", "2")
> .field("name", "Maya")
> .field("totalexp",11.0);
> 
> ```
> 
> Please let me know if above code is correct.We are not getting desired  
> results even after applying the omit\_norms parameter.
> 
> Thanks in advance
> 
> Hiro Gangwani
> 
> --  
> 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/b707663b-7b7b-48cd-ab96-4490a0171ec1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b707663b-7b7b-48cd-ab96-4490a0171ec1%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CAGCwEM9O96SW1Xxac-dhYaZcD9dW%3DD8GCT2rSqVFANkr236%3DYg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9O96SW1Xxac-dhYaZcD9dW%3DD8GCT2rSqVFANkr236%3DYg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:54am UTC](https://discuss.elastic.co/t/document-size-and-score-during-search/15431/3 "2017-07-06T01:54:28Z")

</div>


