Sort by preferred nested object

running docker image docker.elastic.co/elasticsearch/elasticsearch:6.2.3

queries bellow do not return same result
I am trying to sort by nested object, and if main user matches my nested filter, sort by it.
It works as expected if i leave must empty, but any condition in must results in should being ignored

query with must match all
POST my_index/_search
{
  "sort": [
    {
      "user.height": {
        "mode": "max",
        "order": "desc",
        "nested": {
          "path": "user",
          "filter": {
            "bool": {
              "minimum_should_match": 0,
              "must": [
                {
                  "match_all": {}
                }
              ],
              "should": [
                {
                  "term": {
                    "user.main": true
                  }
                }
              ]
            }
          }
        }
      }
    }
  ]
}
response
{
  "took": 10,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": null,
    "hits": [
      {
        "_index": "my_index",
        "_type": "_doc",
        "_id": "1",
        "_score": null,
        "_source": {
          "group": "fans",
          "user": [
            {
              "name": "John",
              "height": 200,
              "main": false
            },
            {
              "name": "Alice",
              "height": 150,
              "main": true
            }
          ]
        },
        "sort": [
          200
        ]
      },
      {
        "_index": "my_index",
        "_type": "_doc",
        "_id": "2",
        "_score": null,
        "_source": {
          "group": "groupies",
          "user": [
            {
              "name": "Malcolm",
              "height": 175,
              "main": true
            }
          ]
        },
        "sort": [
          175
        ]
      }
    ]
  }
}
query with empty must
POST my_index/_search
{
  "sort": [
    {
      "user.height": {
        "mode": "max",
        "order": "desc",
        "nested": {
          "path": "user",
          "filter": {
            "bool": {
              "minimum_should_match": 0,
              "must": [
              ],
              "should": [
                {
                  "term": {
                    "user.main": true
                  }
                }
              ]
            }
          }
        }
      }
    }
  ]
}
response
{
  "took": 15,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": null,
    "hits": [
      {
        "_index": "my_index",
        "_type": "_doc",
        "_id": "2",
        "_score": null,
        "_source": {
          "group": "groupies",
          "user": [
            {
              "name": "Malcolm",
              "height": 175,
              "main": true
            }
          ]
        },
        "sort": [
          175
        ]
      },
      {
        "_index": "my_index",
        "_type": "_doc",
        "_id": "1",
        "_score": null,
        "_source": {
          "group": "fans",
          "user": [
            {
              "name": "John",
              "height": 200,
              "main": false
            },
            {
              "name": "Alice",
              "height": 150,
              "main": true
            }
          ]
        },
        "sort": [
          150
        ]
      }
    ]
  }
}
how to reproduce
PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "user": {
          "type": "nested" 
        }
      }
    }
  }
}

PUT my_index/_doc/1
{
  "group": "fans",
  "user": [
    {
      "name": "John",
      "height": 150,
      "main": true
    },
    {
      "name": "Alice",
      "height": 200,
      "main": false
    }
  ]
}

PUT my_index/_doc/2
{
  "group": "groupies",
  "user": [
    {
      "name": "Malcolm",
      "height": 175,
      "main": true
    }
  ]
}

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