# Sort failed in "NOT\_ANALYZED" field

**URL:** <https://discuss.elastic.co/t/sort-failed-in-not-analyzed-field/8311>\
**Category:** Elasticsearch\
**Created:** [July 4, 2012, 10:16am UTC](https://discuss.elastic.co/t/sort-failed-in-not-analyzed-field/8311 "2012-07-04T10:16:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [July 4, 2012, 10:16am UTC](https://discuss.elastic.co/t/sort-failed-in-not-analyzed-field/8311/1 "2012-07-04T10:16:38Z")

</div>

Hi,

I have a type _user_, where I have a field _title_ for search and I added a  
field _sortable.title_ for sorting purpose, which is not\_analyzed, its  
mapping is as follows :

{"user":{  
"properties":{  
"sortable":{  
"type":"object","properties":{  
"title":{

"type":"string","index":"not\_analyzed"  
}  
}  
},  
"title":{  
"type":"string","index":"analyzed"  
}  
}  
}  
}

and now when I am running the query as follows :

{  
"query":{  
"match\_all":{}  
},  
"sort":{  
"sortable.title":"desc"  
}  
}

OR  
{  
"query":{  
"text":{  
"title":{  
"type":"phrase\_prefix","query":"nar"  
}  
}  
},  
"sort":{  
"sortable.title":"desc"  
}  
}

its returning the following exception :

\*{

- index: es\_5
- shard: 1
- status: 500
- reason: QueryPhaseExecutionException[[es\_5][1]:  
query[ConstantScore(NotDeleted(_:_))],from[0],size[10],sort[\<custom:"sortable.title":  
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@3f28e2\>]:  
Query Failed [Failed to execute main query]]; nested: IOException[Can't  
sort on string types with more than one value per doc, or more than one  
token per field];

},\*\*{\*  
\*

- 
  - 
    - index: es\_5
    - shard: 3
    - status: 500
    - reason: QueryPhaseExecutionException[[es\_5][3]:  
query[ConstantScore(NotDeleted(_:_))],from[0],size[10],sort[\<custom:"sortable.title":  
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@32e46a\>]:  
Query Failed [Failed to execute main query]]; nested: IOException[Can't  
sort on string types with more than one value per doc, or more than one  
token per field];  
}

  - {
    - index: es\_5
    - shard: 2
    - status: 500
    - reason: QueryPhaseExecutionException[[es\_5][2]:  
query[ConstantScore(NotDeleted(_:_))],from[0],size[10],sort[\<custom:"sortable.title":  
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@13204e5\>]:  
Query Failed [Failed to execute main query]]; nested: IOException[Can't  
sort on string types with more than one value per doc, or more than one  
token per field];  
}  
]

\*_}_  
It was working fine earlier with the old data, we just reimported the data  
to elasticsearch, rather this time we strictly added mapping to every  
field,and now its crashing on the same data.  
\*  
\*  
\*  
\*

---

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [July 4, 2012, 10:18am UTC](https://discuss.elastic.co/t/sort-failed-in-not-analyzed-field/8311/2 "2012-07-04T10:18:51Z")

</div>

Hello!

Do you have more than one value in that field by any chance ?

_--_

Regards,

Rafał Kuć

Sematext :: [http://sematext.com/](http://sematext.com/) _:: Solr - Lucene - Nutch - ElasticSearch_

Hi,

I have a type **user** , where I have a field **title** for search and I added a field **sortable.title** for sorting purpose, which is not\_analyzed, its mapping is as follows :

{"user":{

```
"properties":{

     "sortable":{

            "type":"object","properties":{

                                      "title":{

                                         "type":"string","index":"not_analyzed"

                                                    }

                                              }

                  },

      "title":{

              "type":"string","index":"analyzed"

              }

              }  

      }

```

}

and now when I am running the query as follows :

{

```
   "query":{

     "match_all":{}

              },

     "sort":{

        "sortable.title":"desc"

              }

```

}

OR

{

```
   "query":{

     "text":{

           "title":{

               "type":"phrase_prefix","query":"nar"

                   }

              }

            },

     "sort":{

        "sortable.title":"desc"

              }

```

}

its returning the following exception :

**{**

- **index: es\_5**
- **shard: 1**
- **status: 500**
- **reason: QueryPhaseExecutionException[[es\_5][1]: query[ConstantScore(NotDeleted(\*:\*))],from[0],size[10],sort[\<custom:"sortable.title": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@3f28e2\>]: Query Failed [Failed to execute main query]]; nested: IOException[Can't sort on string types with more than one value per doc, or more than one token per field];** 

**},{**

- 

- 

- **index: es\_5**
- **shard: 3**
- **status: 500**
- **reason: QueryPhaseExecutionException[[es\_5][3]: query[ConstantScore(NotDeleted(\*:\*))],from[0],size[10],sort[\<custom:"sortable.title": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@32e46a\>]: Query Failed [Failed to execute main query]]; nested: IOException[Can't sort on string types with more than one value per doc, or more than one token per field];** 

**}**

- **{**

- **index: es\_5**
- **shard: 2**
- **status: 500**
- **reason: QueryPhaseExecutionException[[es\_5][2]: query[ConstantScore(NotDeleted(\*:\*))],from[0],size[10],sort[\<custom:"sortable.title": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@13204e5\>]: Query Failed [Failed to execute main query]]; nested: IOException[Can't sort on string types with more than one value per doc, or more than one token per field];** 

**}**

]

}

It was working fine earlier with the old data, we just reimported the data to elasticsearch, rather this time we strictly added mapping to every field,and now its crashing on the same data.

---

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [July 4, 2012, 10:25am UTC](https://discuss.elastic.co/t/sort-failed-in-not-analyzed-field/8311/3 "2012-07-04T10:25:43Z")

</div>

Is it something related to multi\_field mapping??? I think I am using the  
different field for searching and sorting, so It should not be.but please  
guide me if I am on wrong way.

On Wednesday, 4 July 2012 15:46:38 UTC+5:30, Narinder Kaur wrote:

> Hi,
> 
> I have a type _user_, where I have a field _title_ for search and I added  
> a field _sortable.title_ for sorting purpose, which is not\_analyzed, its  
> mapping is as follows :
> 
> {"user":{  
> "properties":{  
> "sortable":{  
> "type":"object","properties":{  
> "title":{
> 
> "type":"string","index":"not\_analyzed"  
> }  
> }  
> },  
> "title":{  
> "type":"string","index":"analyzed"  
> }  
> }  
> }  
> }
> 
> and now when I am running the query as follows :
> 
> {  
> "query":{  
> "match\_all":{}  
> },  
> "sort":{  
> "sortable.title":"desc"  
> }  
> }
> 
> OR  
> {  
> "query":{  
> "text":{  
> "title":{  
> "type":"phrase\_prefix","query":"nar"  
> }  
> }  
> },  
> "sort":{  
> "sortable.title":"desc"  
> }  
> }
> 
> its returning the following exception :
> 
> \*{
> 
> - index: es\_5
> - shard: 1
> - status: 500
> - reason: QueryPhaseExecutionException[[es\_5][1]:  
> query[ConstantScore(NotDeleted(_:_))],from[0],size[10],sort[\<custom:"sortable.title":  
> org.elasticsearch.index.field.data.strings.StringFieldDataType$1@3f28e2\>]:  
> Query Failed [Failed to execute main query]]; nested: IOException[Can't  
> sort on string types with more than one value per doc, or more than one  
> token per field];
> 
> },\*\*{\*  
> \*
> 
> - 
> - 
> - index: es\_5
> - shard: 3
> - status: 500
> - reason: QueryPhaseExecutionException[[es\_5][3]:  
> query[ConstantScore(NotDeleted(_:_))],from[0],size[10],sort[\<custom:"sortable.title":  
> org.elasticsearch.index.field.data.strings.StringFieldDataType$1@32e46a\>]:  
> Query Failed [Failed to execute main query]]; nested: IOException[Can't  
> sort on string types with more than one value per doc, or more than one  
> token per field];  
> }
> 
> - {
> - index: es\_5
> - shard: 2
> - status: 500
> - reason: QueryPhaseExecutionException[[es\_5][2]:  
> query[ConstantScore(NotDeleted(_:_))],from[0],size[10],sort[\<custom:"sortable.title":  
> org.elasticsearch.index.field.data.strings.StringFieldDataType$1@13204e5\>]:  
> Query Failed [Failed to execute main query]]; nested: IOException[Can't  
> sort on string types with more than one value per doc, or more than one  
> token per field];  
> }  
> ]
> 
> \*_}_  
> It was working fine earlier with the old data, we just reimported the  
> data to elasticsearch, rather this time we strictly added mapping to every  
> field,and now its crashing on the same data.  
> \*  
> \*  
> \*  
> \*

---

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [July 4, 2012, 10:28am UTC](https://discuss.elastic.co/t/sort-failed-in-not-analyzed-field/8311/4 "2012-07-04T10:28:06Z")

</div>

sortable.title basically contains the name(including first name and last  
name). but as the sortable.title is _not\_analyzed_ field, so it should be  
treated as a single string, correct me if I am wrong.

On Wednesday, 4 July 2012 15:48:51 UTC+5:30, Rafał Kuć wrote:

> Hello!
> 
> Do you have more than one value in that field by any chance ?
> 
> \*--  
> Regards,  
> Rafał Kuć  
> Sematext :: _[http://sematext.com/](http://sematext.com/)_ :: Solr - Lucene - Nutch -  
> Elasticsearch
> 
> - 
> 
> Hi,
> 
> I have a type _user_, where I have a field _title_ for search and I added  
> a field _sortable.title_ for sorting purpose, which is not\_analyzed, its  
> mapping is as follows :
> 
> {"user":{  
> "properties":{  
> "sortable":{  
> "type":"object","properties":{  
> "title":{
> 
> "type":"string","index":"not\_analyzed"  
> }  
> }  
> },  
> "title":{  
> "type":"string","index":"analyzed"  
> }  
> }  
> }  
> }
> 
> and now when I am running the query as follows :
> 
> {  
> "query":{  
> "match\_all":{}  
> },  
> "sort":{  
> "sortable.title":"desc"  
> }  
> }
> 
> OR  
> {  
> "query":{  
> "text":{  
> "title":{  
> "type":"phrase\_prefix","query":"nar"  
> }  
> }  
> },  
> "sort":{  
> "sortable.title":"desc"  
> }  
> }
> 
> its returning the following exception :
> 
> \*{  
> \*
> 
> - _index: es\_5_
> - _shard: 1_
> - _status: 500_
> - _reason: QueryPhaseExecutionException[[es\_5][1]:  
> query[ConstantScore(NotDeleted(_:\*))],from[0],size[10],sort[\<custom:"sortable.title":  
> org.elasticsearch.index.field.data.strings.StringFieldDataType$1@3f28e2\>]:  
> Query Failed [Failed to execute main query]]; nested: IOException[Can't  
> sort on string types with more than one value per doc, or more than one  
> token per field]; \*
> 
> \*},{  
> \*
> 
> - 
> 
> - 
> 
> - _index: es\_5_
> - _shard: 3_
> - _status: 500_
> - _reason: QueryPhaseExecutionException[[es\_5][3]:  
> query[ConstantScore(NotDeleted(_:\*))],from[0],size[10],sort[\<custom:"sortable.title":  
> org.elasticsearch.index.field.data.strings.StringFieldDataType$1@32e46a\>]:  
> Query Failed [Failed to execute main query]]; nested: IOException[Can't  
> sort on string types with more than one value per doc, or more than one  
> token per field]; \*
> 
> \*}  
> \*
> 
> - _{_
> 
> - _index: es\_5_
> 
> - _shard: 2_
> 
> - _status: 500_
> 
> - _reason: QueryPhaseExecutionException[[es\_5][2]:  
> query[ConstantScore(NotDeleted(_:\*))],from[0],size[10],sort[\<custom:"sortable.title":  
> org.elasticsearch.index.field.data.strings.StringFieldDataType$1@13204e5\>]:  
> Query Failed [Failed to execute main query]]; nested: IOException[Can't  
> sort on string types with more than one value per doc, or more than one  
> token per field]; \*
> 
> \*}
> 
> ]
> 
> }
> 
> - It was working fine earlier with the old data, we just reimported the  
> data to elasticsearch, rather this time we strictly added mapping to every  
> field,and now its crashing on the same data.

---

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [July 4, 2012, 10:30am UTC](https://discuss.elastic.co/t/sort-failed-in-not-analyzed-field/8311/5 "2012-07-04T10:30:43Z")

</div>

Hello!

Are you indexing it as a concatenated value or as two separate values, but in a single field ? If the second option is true, than you have two separate values in the field, of course not analyzed.

_--_

Regards,

Rafał Kuć

Sematext :: [http://sematext.com/](http://sematext.com/) _:: Solr - Lucene - Nutch - ElasticSearch_

sortable.title basically contains the name(including first name and last name). but as the sortable.title is **not\_analyzed** field, so it should be treated as a single string, correct me if I am wrong.

On Wednesday, 4 July 2012 15:48:51 UTC+5:30, Rafał Kuć wrote:

Hello!

Do you have more than one value in that field by any chance ?

_--_

Regards,

Rafał Kuć

Sematext :: [http://sematext.com/](http://sematext.com/) _:: Solr - Lucene - Nutch - ElasticSearch_

Hi,

I have a type **user** , where I have a field **title** for search and I added a field **sortable.title** for sorting purpose, which is not\_analyzed, its mapping is as follows :

{"user":{

```
"properties":{

     "sortable":{

            "type":"object","properties":{

                                      "title":{

                                         "type":"string","index":"not_analyzed"

                                                    }

                                              }

                  },

      "title":{

              "type":"string","index":"analyzed"

              }

              }  

      }

```

}

and now when I am running the query as follows :

{

```
   "query":{

     "match_all":{}

              },

     "sort":{

        "sortable.title":"desc"

              }

```

}

OR

{

```
   "query":{

     "text":{

           "title":{

               "type":"phrase_prefix","query":"nar"

                   }

              }

            },

     "sort":{

        "sortable.title":"desc"

              }

```

}

its returning the following exception :

**{**

- **index: es\_5**
- **shard: 1**
- **status: 500**
- **reason: QueryPhaseExecutionException[[es\_5][1]: query[ConstantScore(NotDeleted(\*:\*))],from[0],size[10],sort[\<custom:"sortable.title": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@3f28e2\>]: Query Failed [Failed to execute main query]]; nested: IOException[Can't sort on string types with more than one value per doc, or more than one token per field];** 

**},{**

- 

- 

- **index: es\_5**
- **shard: 3**
- **status: 500**
- **reason: QueryPhaseExecutionException[[es\_5][3]: query[ConstantScore(NotDeleted(\*:\*))],from[0],size[10],sort[\<custom:"sortable.title": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@32e46a\>]: Query Failed [Failed to execute main query]]; nested: IOException[Can't sort on string types with more than one value per doc, or more than one token per field];** 

**}**

- **{**

- **index: es\_5**
- **shard: 2**
- **status: 500**
- **reason: QueryPhaseExecutionException[[es\_5][2]: query[ConstantScore(NotDeleted(\*:\*))],from[0],size[10],sort[\<custom:"sortable.title": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@13204e5\>]: Query Failed [Failed to execute main query]]; nested: IOException[Can't sort on string types with more than one value per doc, or more than one token per field];** 

**}**

]

}

It was working fine earlier with the old data, we just reimported the data to elasticsearch, rather this time we strictly added mapping to every field,and now its crashing on the same data.

---

<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, 3:21am UTC](https://discuss.elastic.co/t/sort-failed-in-not-analyzed-field/8311/6 "2017-07-06T03:21:32Z")

</div>


