# Searching and Sorting on ElasticSearch

**URL:** https://discuss.elastic.co/t/searching-and-sorting-on-elasticsearch/21262
**Category:** Elasticsearch
**Created:** [December 15, 2014, 9:43pm UTC](https://discuss.elastic.co/t/searching-and-sorting-on-elasticsearch/21262 "2014-12-15T21:43:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Yasmany\_Cubela](https://avatars.discourse-cdn.com/v4/letter/y/6a8cbe/32.png) [@Yasmany\_Cubela](https://discuss.elastic.co/u/Yasmany_Cubela)
#### Post date: [December 15, 2014, 9:43pm UTC](https://discuss.elastic.co/t/searching-and-sorting-on-elasticsearch/21262/1 "2014-12-15T21:43:31Z")

</div>

Hi im implementing ES as my SE and i have some questions about what im  
doing wrong.

The main idea its to have a set of posts that i want to search over some  
text fields and sort the results by relevance and then by creation date  
(one of the fields). Im using node js with the default es library.

Here its my mapping:

{  
"version": 1,  
"conf": {  
"settings": {  
"analysis": {  
"filter": {  
"snowball": {  
"type": "snowball",  
"language": "English"  
},  
"english\_stemmer": {  
"type": "stemmer",  
"language": "english"  
},  
"english\_possessive\_stemmer": {  
"type": "stemmer",  
"language": "possessive\_english"  
},  
"stopwords": {  
"type": "stop",  
"stopwords": ["_english_"]  
},  
"worddelimiter": {  
"type": "word\_delimiter"  
}  
},  
"tokenizer": {  
"nGram": {  
"type": "nGram",  
"min\_gram": 3,  
"max\_gram": 20  
}  
},  
"analyzer": {  
"custom\_analyzer": {  
"type": "custom",  
"tokenizer": "nGram",  
"filter": [  
"stopwords",  
"asciifolding",  
"lowercase",  
"snowball",  
"english\_stemmer",  
"english\_possessive\_stemmer",  
"worddelimiter"  
]  
},  
"custom\_search\_analyzer": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": [  
"stopwords",  
"asciifolding",  
"lowercase",  
"snowball",  
"english\_stemmer",  
"english\_possessive\_stemmer",  
"worddelimiter"  
]  
}  
}  
}  
},  
"mappings": {  
"posts": {  
"model": "Post",  
"properties": {  
"id": {  
"type": "long"  
},  
"title": {  
"type": "string",  
"analyzer": "custom\_analyzer",  
"boost": 5  
},  
"description": {  
"type": "string",  
"analyzer": "custom\_analyzer",  
"boost": 4  
},  
"categories": {  
"type": "string",  
"analyzer": "custom\_analyzer"  
},  
"seller": {  
"type": "object",  
"properties": {  
"id": {  
"type": "long"  
},  
"username": {  
"type": "string",  
"analyzer": "custom\_analyzer",  
"boost": 1  
},  
"firstName": {  
"type": "string",  
"analyzer": "custom\_analyzer",  
"boost": 3  
},  
"lastName": {  
"type": "string",  
"analyzer": "custom\_analyzer",  
"boost": 2  
}  
}  
},  
"marketPrice": {  
"type": "float"  
},  
"currentPrice": {  
"type": "float"  
},  
"discount": {  
"type": "float"  
},  
"commentsCount": {  
"type": "integer",  
"index": "not\_analyzed"  
},  
"likesCount": {  
"type": "integer",  
"index": "not\_analyzed"  
},  
"created": {  
"type": "date",  
"index": "not\_analyzed"  
},  
"modified": {  
"type": "date",  
"index": "not\_analyzed"  
}  
}  
}  
}  
}}

I have indexed 10 documents:

| id | title | description | market\_price | item\_condition | iso | comment\_count | created |  
| 1 | Post 1 | Post 1 Description | 1 | 1 | 1 | 1 | 2014/01/01 |  
| 2 | Post 2 | Post 2 Description | 1 | 1 | 1 | 1 | 2014/01/02 |  
| 3 | Post 3 | Post 3 Description | 1 | 1 | 1 | 1 | 2014/01/03 |  
| 4 | Post 4 | Post 4 Description | 1 | 1 | 1 | 1 | 2014/01/04 |  
| 5 | Post 5 | Post 5 Description | 1 | 1 | 1 | 1 | 2014/01/05 |  
| 6 | Post 6 | Post 6 Description | 1 | 1 | 1 | 1 | 2014/01/06 |  
| 7 | Post 7 | Post 7 Description | 1 | 1 | 1 | 1 | 2014/01/07 |  
| 8 | Post 8 | Post 8 Description | 1 | 1 | 1 | 1 | 2014/01/08 |  
| 9 | Post 9 | Post 9 Description | 1 | 1 | 1 | 1 | 2014/01/09 |  
| 10 | Post 10 | Post 10 Description | 1 | 1 | 1 | 1 | 2014/01/010 |

Assume that the seller info its there two, i dont add it here because the  
post will be extensive.

My query its:

GET /clamour\_develop/\_search{  
"query": {  
"multi\_match": {  
"query": "post 1",  
"fields": ["title", "description", "seller.first\_name", "seller.last\_name", "seller.username"],  
"analyzer": "custom\_search\_analyzer"  
}  
},  
"sort": [  
{  
"\_score":{  
"order": "desc"  
}  
},{  
"created": {  
"order": "desc"  
}  
}  
]  
}

I expect to receive the documents in the order

Post 1  
Post 10  
Post 9  
Post 8  
Post 7  
Post 6  
Post 5  
Post 4  
Post 3  
Post 2

But i get

Post 1  
Post 10  
Post 8  
Post 3  
Post 9  
Post 7  
Post 6  
Post 4  
Post 2  
Post 5

What im doing wrong?

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/527a46e0-985a-45dd-9a2f-57108c738a97%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/527a46e0-985a-45dd-9a2f-57108c738a97%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, 12:43am UTC](https://discuss.elastic.co/t/searching-and-sorting-on-elasticsearch/21262/2 "2017-07-06T00:43:39Z")

</div>


