# Can't order by \_boost field, even when "index":"not\_analyzed"

**URL:** <https://discuss.elastic.co/t/cant-order-by--boost-field-even-when-index-not-analyzed/15909>\
**Category:** Elasticsearch\
**Created:** [February 19, 2014, 9:36pm UTC](https://discuss.elastic.co/t/cant-order-by--boost-field-even-when-index-not-analyzed/15909 "2014-02-19T21:36:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon44344346](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@anon44344346](https://discuss.elastic.co/u/anon44344346)\
**Post date:** [February 19, 2014, 9:36pm UTC](https://discuss.elastic.co/t/cant-order-by--boost-field-even-when-index-not-analyzed/15909/1 "2014-02-19T21:36:25Z")

</div>

according to martijin's remarks on  
[https://groups.google.com/forum/#!topic/elasticsearch/A5DSgvnTnC0](https://groups.google.com/forum/#!topic/elasticsearch/A5DSgvnTnC0)  
and also this issue  
[https://github.com/elasticsearch/elasticsearch/issues/3752](https://github.com/elasticsearch/elasticsearch/issues/3752) ,

search results should be sortable by \_boost field.

my particular setup:

{  
"product": {  
"properties": {  
"\_boost": {  
"type": "float",  
"null\_value": 1.0,  
"index": "not\_analyzed"  
}  
}  
}

when using a match\_all query, I can sort for any numeric field, but the  
"\_boost", that does not work. I'm using 0.90.10

Also, I don't know if this is related, but when I try to get the mapping  
via localhost:9200/index\_name/\_mapping , the \_boost field doesn't show up.  
I guess it's because of its special nature.

--  
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/e22fe979-1978-4e5d-8a7c-73a6dd238cdf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e22fe979-1978-4e5d-8a7c-73a6dd238cdf%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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 20, 2014, 12:07am UTC](https://discuss.elastic.co/t/cant-order-by--boost-field-even-when-index-not-analyzed/15909/2 "2014-02-20T00:07:38Z")

</div>

The boost field, like other special fields such as timestamp and id, is set  
at the root level of a type, not as a property:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Perhaps I should have added this confusion as yet another reason why to  
avoid the boost field:

> **[Document boosting in Elasticsearch](http://blog.brusic.com/2014/02/document-boosting-in-elasticsearch.html)**
>
> There has been some discussion on the Elasticsearch mailing list lately about applying index-time boosts at the document level, aka documen...

--  
Ivan

On Wed, Feb 19, 2014 at 1:36 PM, JoeZ99 [jzarate@gmail.com](mailto:jzarate@gmail.com) wrote:

> according to martijin's remarks on  
> [Redirecting to Google Groups](https://groups.google.com/forum/#!topic/elasticsearch/A5DSgvnTnC0)  
> and also this issue  
> [Allow \_boost field to be indexed and stored in mapping · Issue #3752 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3752) ,
> 
> search results should be sortable by \_boost field.
> 
> my particular setup:
> 
> {  
> "product": {  
> "properties": {  
> "\_boost": {  
> "type": "float",  
> "null\_value": 1.0,  
> "index": "not\_analyzed"  
> }  
> }  
> }
> 
> when using a match\_all query, I can sort for any numeric field, but the  
> "\_boost", that does not work. I'm using 0.90.10
> 
> Also, I don't know if this is related, but when I try to get the mapping  
> via localhost:9200/index\_name/\_mapping , the \_boost field doesn't show up.  
> I guess it's because of its special nature.
> 
> --  
> 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/e22fe979-1978-4e5d-8a7c-73a6dd238cdf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e22fe979-1978-4e5d-8a7c-73a6dd238cdf%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/CALY%3DcQA-Xm9bwsG54uMzduqXcV2\_%2BCPWrcD5zJWHFJMnLAzPYA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA-Xm9bwsG54uMzduqXcV2_%2BCPWrcD5zJWHFJMnLAzPYA%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:** ![anon44344346](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@anon44344346](https://discuss.elastic.co/u/anon44344346)\
**Post date:** [February 24, 2014, 2:45pm UTC](https://discuss.elastic.co/t/cant-order-by--boost-field-even-when-index-not-analyzed/15909/3 "2014-02-24T14:45:42Z")

</div>

Well, after a long hair-stretching weekend, I seem to have hit a bug or, at  
least, unexpected behavior

I've tried all possible combinations, and I think something's not working  
as it should.

first what seemed to be more logical:

{  
"type1": {  
"\_boost": {"name": "df\_boost", "null\_value": 1.0},  
"properties": {  
"df\_boost": {"type": "float", "index": "not\_analyzed"}  
}  
}  
}

I produced the following mapping

```
    "type1": {
        "_boost": {
            "name": "df_boost",
            "null_value": 1
        },
        "properties": {
            "extra_field": {
                "type": "double"
            }
        }
    }
}

```

but after inserting some doc with a "df\_boost" value, trying make a sorted  
query:

{  
"query": { "match\_all": {}},  
"sort": ["df\_boost"]  
}

sort wasn't working

{  
"took": 8,  
"hits": {

```
    "total": 1,
    "max_score": null,
    "hits": [
        {
            "_index": "tito",
            "_type": "type1",
            "_id": "Hbcqp5yqQ5GL1YAcXcHdXw",
            "_score": null,
            "_source": {
                "field": "value",
                "df_boost": 34
            },
            "sort": [
                "Infinity"
            ]
        }
    ]
}

```

}

(check the "sort": ["Infinity"])

then I tried putting "index": "analyzed" in the root level definition.

{  
"mappings":{  
"type1":{  
"\_boost": {"name": "df\_boost", "null\_value": 1.0, "index":  
"not\_analyzed"},  
"properties": {

```
      "extra_field": {"type": "double"}

```

}  
}  
}  
}

_but an exception is raised then:_

[2014-02-24 09:32:03,365][WARN][indices.cluster] [Master Khan] [  
tito] failed to add mapping [type1], source [{"type1":{"\_boost":{"name":  
"df\_boost","null\_value":1.0,"index":true},"properties":{"extra\_field":{  
"type":"double"}}}}]  
org.elasticsearch.index.mapper.MapperParsingException: Wrong value forindex  
[true] for field [df\_boost]  
at org.elasticsearch.index.mapper.core.TypeParsers.parseIndex(  
TypeParsers.java:194)  
at org.elasticsearch.index.mapper.core.TypeParsers.parseField(  
TypeParsers.java:76)  
at org.elasticsearch.index.mapper.core.TypeParsers.parseNumberField(  
TypeParsers.java:51)  
at org.elasticsearch.index.mapper.internal.  
BoostFieldMapper$TypeParser.parse(BoostFieldMapper.java:99)  
at org.elasticsearch.index.mapper.DocumentMapperParser.parse(  
DocumentMapperParser.java:235)  
at org.elasticsearch.index.mapper.DocumentMapperParser.  
parseCompressed(DocumentMapperParser.java:183)  
at org.elasticsearch.index.mapper.MapperService.parse(MapperService.  
java:322)  
at org.elasticsearch.index.mapper.MapperService.merge(MapperService.  
java:200)  
at org.elasticsearch.indices.cluster.IndicesClusterStateService.  
processMapping(IndicesClusterStateService.java:405)  
at org.elasticsearch.indices.cluster.IndicesClusterStateService.  
applyMappings(IndicesClusterStateService.java:360)  
at org.elasticsearch.indices.cluster.IndicesClusterStateService.  
clusterChanged(IndicesClusterStateService.java:179)  
at org.elasticsearch.cluster.service.  
InternalClusterService$UpdateTask.run(InternalClusterService.java:416)  
at org.elasticsearch.common.util.concurrent.  
PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(  
PrioritizedEsThreadPoolExecutor.java:135)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(  
ThreadPoolExecutor.java:1146)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(  
ThreadPoolExecutor.java:615)  
at java.lang.Thread.run(Thread.java:679)

it looks like "index":"not\_analyzed" is not something that should be  
defined in "\_boost".

anyway, now the mapping is:

"type1": {  
"\_boost": {  
"name": "df\_boost",  
"null\_value": 1,  
"index": true  
},  
"properties": {  
"extra\_field": {  
"type": "double"  
}  
}  
}

see how a new "index": true has appeared, in spite of the previous  
exception being raised.

and now, sorted query work!

{  
"query": { "match\_all": {}},  
"sort": ["df\_boost"]  
}

provdes:

{  
"took": 8,

```
"hits": {
    "total": 1,
    "max_score": null,
    "hits": [
        {
            "_index": "tito",
            "_type": "type1",
            "_id": "6r-8C64RSNuPQ1vGPENK6g",
            "_score": null,
            "_source": {
                "field": "value",
                "df_boost": 34
            },
            "sort": [
                34
            ]
        }
    ]
}

```

}

Notice how no there is a value for the "sort" field.

But, because this exception raising, my python client (pyes) and probably  
others, doesn't seem to fulfill the mapping creation, so If I want this  
feature, I have to use the API "on straight" and also let the system throw  
an exception for no good reason.

;-(  
On Wednesday, February 19, 2014 4:36:25 PM UTC-5, JoeZ99 wrote:

> according to martijin's remarks on  
> [Redirecting to Google Groups](https://groups.google.com/forum/#!topic/elasticsearch/A5DSgvnTnC0)  
> and also this issue  
> [Allow \_boost field to be indexed and stored in mapping · Issue #3752 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3752) ,
> 
> search results should be sortable by \_boost field.
> 
> my particular setup:
> 
> {  
> "product": {  
> "properties": {  
> "\_boost": {  
> "type": "float",  
> "null\_value": 1.0,  
> "index": "not\_analyzed"  
> }  
> }  
> }
> 
> when using a match\_all query, I can sort for any numeric field, but the  
> "\_boost", that does not work. I'm using 0.90.10
> 
> Also, I don't know if this is related, but when I try to get the mapping  
> via localhost:9200/index\_name/\_mapping , the \_boost field doesn't show up.  
> I guess it's because of its special nature.

--  
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/afa0490e-d668-4912-8ad0-145e54354a4d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/afa0490e-d668-4912-8ad0-145e54354a4d%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:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 24, 2014, 10:14pm UTC](https://discuss.elastic.co/t/cant-order-by--boost-field-even-when-index-not-analyzed/15909/4 "2014-02-24T22:14:48Z")

</div>

Yup, this is a known bug. Since \_boost is being deprecated and replaced by  
function\_score, this will likely not be fixed. For now if you want to sort  
on a "boost" value, either remove the \_boost from your mapping, or  
introduce another field that you don't refer to from \_boost.

--  
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/026c733c-9077-434d-b92d-9d8dacbf9f50%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/026c733c-9077-434d-b92d-9d8dacbf9f50%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:** ![anon44344346](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@anon44344346](https://discuss.elastic.co/u/anon44344346)\
**Post date:** [February 25, 2014, 3:01am UTC](https://discuss.elastic.co/t/cant-order-by--boost-field-even-when-index-not-analyzed/15909/5 "2014-02-25T03:01:07Z")

</div>

Ok, .

Good to know, I wish I knew this a few days before 😉 I was really loosing  
my mind on this!!

yet another reason for dropping indexing time defined boost, I guess. I  
really wish there were any way of defining per-document boost at index  
time.

txs!

On Monday, February 24, 2014 5:14:48 PM UTC-5, Binh Ly wrote:

> Yup, this is a known bug. Since \_boost is being deprecated and replaced by  
> function\_score, this will likely not be fixed. For now if you want to sort  
> on a "boost" value, either remove the \_boost from your mapping, or  
> introduce another field that you don't refer to from \_boost.

--  
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/b1bd446d-8fc9-4d58-84aa-f86f6d3a43e1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b1bd446d-8fc9-4d58-84aa-f86f6d3a43e1%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:** ![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:47am UTC](https://discuss.elastic.co/t/cant-order-by--boost-field-even-when-index-not-analyzed/15909/6 "2017-07-06T01:47:36Z")

</div>


