Help with sorting by nested field

I'm trying to sort the resulting documents of a nested query, by another nested field. I've based this on the original documentation, but can't seem to make it work. Does anyone know what the problem might be? Here's the query that I use:

{
    "query": {
      "bool": {
        "filter": [
          {
            "nested": {
              "path": "properties",
              "query": {
                "bool": {
                  "filter": [
                    {
                      "match": {
                        "properties.key": "PROPERTY_TO_FILTER_DOCUMENTS_ON"
                      }
                    },
                    {
                      "match": {
                        "properties.value": "yes"
                      }
                    }
                  ]
                }
              }
            }
          }
        ]
      }
    },
    "sort": [
      {
        "properties.value.keyword": {
          "order": "asc",
          "nested": {
            "path": "properties",
            "filter": {
              "term": {
                "properties.key": "PROPERTY_TO_SORT_ON"
              }
            }
          }
        }
      }
    ],
    "size": 1000,
    "_source": [
      "field1",
      "field2",
      "field3",
      "field4",
      "field5"
    ]
  }

For anyone having the same problem, I was missing a ".keyword"

{
    "query": {
      "bool": {
        "filter": [
          {
            "nested": {
              "path": "properties",
              "query": {
                "bool": {
                  "filter": [
                    {
                      "match": {
                        "properties.key": "PROPERTY_TO_FILTER_DOCUMENTS_ON"
                      }
                    },
                    {
                      "match": {
                        "properties.value": "yes"
                      }
                    }
                  ]
                }
              }
            }
          }
        ]
      }
    },
    "sort": [
      {
        "properties.value.keyword": {
          "order": "asc",
          "nested": {
            "path": "properties",
            "filter": {
              "term": {
                "properties.key**.keyword**": "PROPERTY_TO_SORT_ON"
              }
            }
          }
        }
      }
    ],
    "size": 1000,
    "_source": [
      "field1",
      "field2",
      "field3",
      "field4",
      "field5"
    ]
  }

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