• Sorting in elasticsearch

    Posted by Tarun Tyagi | Last Updated: 01-Jul-16

    If you want to sort your data in albhabetical older on the bases of particular field then you need to following these steps:

    Step 1. You need to do setting of  your index.

    curl -XPUT 'http://localhost:9200/your_index_name' -d '{
      "settings": {
        "analysis": {
          "analyzer": {
            "case_insensitive_sort": {
              "tokenizer": "keyword",    
              "filter":  [ "lowercase" ] 


    Step 2 . After update the settings you need to do mapping for your data

    for example we have data of students:




    Now we want to sort our data on the bases of name .So mapping is
     curl -XPUT 'http://localhost:9200/your_index_name/_mapping/students' -d '{  


    Step 3. After update the maping insert data into elasticsearch

    insert data using this api : http://localhost:9200/your_index_name/students/uniqueId

    curl -XPUT 'http://localhost:9200/your_index_name/students/1' -d '{"name":"titu","address":"ghaziabad","rollNo":20}'
    curl -XPUT 'http://localhost:9200/your_index_name/students/2' -d '{"name":"Sonu","address":"agra","rollNo":1}'
    curl -XPUT 'http://localhost:9200/your_index_name/students/3' -d '{"name":"anu","address":"delhi","rollNo":10}'


    Step 4. Get your data in sorting order

     curl -XGET 'http://localhost:9200/your_index_name/students/_search?sort=name.lower_case_sort'



Tags: nosql

Mobile Applications

Video Content

Bigdata & NoSQL

SaaS Applications



Alexa Certified Site Stats for