Conditional sort

Hi, I have the following index:

                "norm_id": {
                    "type": "keyword"
                },
                "precedence": {
                    "type": "float"
                },
                "root_norm_id": {
                    "type": "keyword"
                },
                "status_id": {
                    "type": "integer"
                },
                "title": {
                    "type": "text"
                },
                "type_id": {
                    "type": "integer"
                }

And I need to get all documents that have root_norm_id = some ID and then sort by norm_id and precedence respectively. Also, I need that all documents with type_id = 3 to be at the bottom, but I don't know how to do that. Can someone help me?

Thanks.

Try this:

   {
  "query": {
    "function_score": {
      "query": {
        "match": {
          "root_norm_id": 1234
        }
      },
      "boost": "5",
      "functions": [
        {
          "filter": {
            "match_all": {}
          },
          "weight": 1
        },
        {
          "filter": {
            "match": {
              "type_id ": 3
            }
          },
          "weight": 2
        }
      ]
    }
  },
  "sort": [
    {
      "_score": {
        "order": "asc"
      },
      "norm_id ": {
        "order": "asc"
      },
      "precedence ": {
        "order": "asc"
      }
    }
  ]
}

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