Sorting with a custom order - ES 5.6

I'm trying to change the sorting to use an specific order, but it doesn't seem to be working. The order never changes to what I've set up. For the example below, records with posted state should come first

This is the current JSON I have:

GET test_index/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "_script": {
        "type": "string",
        "script": {
          "lang": "painless",
          "source": "doc['state'].value",
          "params": {
            "factor": {
              "posted": 0,
              "draft": 1
            },
            "order": "desc"
          }
        }
      }
    }
  ],
  "_source": "{state}"
}

// And this is the mapping

    "state": {
      "type": "keyword",
      "fields": {
        "analyzed": {
          "type": "text",
          "analyzer": "searchkick_index"
        }
      },
      "include_in_all": true,
      "ignore_above": 30000
    }

Does it make sense? Is it clear enough?
Thanks in advance

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.