Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Creating an index with multiple sort fields in Elasticsearch 7.17.9

Currently I’m learning and still a newbie to Elasticsearch.

I’m trying to create an index with multiple sort fields (id, created_at). My plan is to try using the search_after parameter in the search function from Python Elasticsearch Client.

Here is the query I’ve already tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

PUT /my-index
{
  "settings": {
    "index":[
      {
        "sort.field": "created_at", 
        "sort.order": "asc"
      },
      {
        "sort.field": "id", 
        "sort.order": "asc"
      }
    ]
  },
  "mappings": {
    "properties": {
      "id": {
        "type": "keyword",
        "doc_values": true
      },
      "name": {
        "type": "keyword"
      },
      "created_at": {
        "type": "date"
      }
    }
  }
}

But, I got an error like this:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "settings_exception",
        "reason" : "Failed to load settings from [{\"index\":[{\"sort.field\":\"created_at\",\"sort.order\":\"asc\"},{\"sort.field\":\"id\",\"sort.order\":\"asc\"}]}]"
      }
    ],
    "type" : "settings_exception",
    "reason" : "Failed to load settings from [{\"index\":[{\"sort.field\":\"created_at\",\"sort.order\":\"asc\"},{\"sort.field\":\"id\",\"sort.order\":\"asc\"}]}]",
    "caused_by" : {
      "type" : "illegal_state_exception",
      "reason" : "only value lists are allowed in serialized settings"
    }
  },
  "status" : 500
}

Please help me. Thanks in advance!

>Solution :

You need to do it like this:

PUT /my-index
{
  "settings": {
    "index": {
      "sort.field": [ "created_at", "id" ], 
      "sort.order": [ "asc", "asc" ]       
    }
  },
  ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading