# Sorting on the not analyzed text

**URL:** <https://discuss.elastic.co/t/sorting-on-the-not-analyzed-text/8986>\
**Category:** Elasticsearch\
**Created:** [September 11, 2012, 10:18am UTC](https://discuss.elastic.co/t/sorting-on-the-not-analyzed-text/8986 "2012-09-11T10:18:11Z")\
**Posts on this page:** 3\
**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:** [September 11, 2012, 10:18am UTC](https://discuss.elastic.co/t/sorting-on-the-not-analyzed-text/8986/1 "2012-09-11T10:18:11Z")

</div>

Hi,

```
      I have a type "*user*" where I am storing the user's data. its 

```

having one of the column "_name_" having the mapping of string and \*analyzed  
\*.

Now lets says users have the names as

joe cartano  
carter swan

Now my requirement is that if i search for term "_cart_", then it should  
search both of above users, but carter swan should get higher score than  
the joe cartano. I can not user the sort clause here, as i need not to sort  
it alphabetically, I am using the custom\_score\_filter to assign external  
scoring and i want to give the priority to _first name_, although first  
name and last name are stored together in a single attribute "_name_".

Can someone help me out this please. This should be a simple sorting issue,  
but I can not find the solution except the one where i save first name and  
last name separate.

--

---

<div class="post-metadata">

**Author:** ![Keith\_Webster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/keith_webster/32/1532_2.png) [@Keith\_Webster](https://discuss.elastic.co/u/Keith_Webster)\
**Post date:** [September 11, 2012, 2:05pm UTC](https://discuss.elastic.co/t/sorting-on-the-not-analyzed-text/8986/2 "2012-09-11T14:05:43Z")

</div>

Hey Narinder,

If you supplied a gist it would make answering this so much easier but I'll  
attempt to answer the best I can:

1. If you want to sort on the field then you should be doing so on a  
not\_analyzed field (either change the mapping to not\_analyzed instead of  
analyzed or change it to a multi field with both analyzed and not\_analyzed  
properties). I do believe you mentioned that you don't want to sort anyway,  
but I just wanted to mention this anyway.
2. Is there a reason why you can't split the name into a first\_name and  
last\_name? If so you could then add a boost to the first\_name during  
queries that would push it to the top over last\_name matches.
3. Just an fyi but if you search for "cart" there's no reason why  
elasticsearch would choose one of your example names over the other. I'm  
not sure what analyzers and filters you are using during indexing or if you  
are just using a wildcard during the actually searching but I can't see any  
reason why either would have relevancy over the other.

Hopefully this helps but if not add a gist with your exact scenario and  
that should make it fully clear.

On Tue, Sep 11, 2012 at 5:18 AM, Narinder Kaur [narinder.kaur@izap.in](mailto:narinder.kaur@izap.in)wrote:

> Hi,
> 
> ```
> I have a type "*user*" where I am storing the user's data. its
> 
> ```
> 
> having one of the column "_name_" having the mapping of string and \*  
> analyzed\*.
> 
> Now lets says users have the names as
> 
> joe cartano  
> carter swan
> 
> Now my requirement is that if i search for term "_cart_", then it should  
> search both of above users, but carter swan should get higher score than  
> the joe cartano. I can not user the sort clause here, as i need not to sort  
> it alphabetically, I am using the custom\_score\_filter to assign external  
> scoring and i want to give the priority to _first name_, although first  
> name and last name are stored together in a single attribute "_name_".
> 
> Can someone help me out this please. This should be a simple sorting  
> issue, but I can not find the solution except the one where i save first  
> name and last name separate.
> 
> --

--

---

<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:13am UTC](https://discuss.elastic.co/t/sorting-on-the-not-analyzed-text/8986/3 "2017-07-06T03:13:11Z")

</div>


