I have a mapping with the following (omitted other properties for brevity):

{
  "index-name" : {
    "mappings" : {
      "index-type" : {
        "properties" : {
          "history" : {
            "properties" : {
              "valuations" : {
                "type" : "nested",
                "include_in_root" : true,
                "properties" : {
                  "confidence" : {
                    "type" : "integer"
                  },
                  "date" : {
                    "type" : "date",
                    "format" : "dateOptionalTime"
                  },
                  "lowerPrice" : {
                    "type" : "integer"
                  },
                  "precision" : {
                    "type" : "integer"
                  },
                  "upperPrice" : {
                    "type" : "integer"
                  }
                }
              }
            }
          },
          "id" : {
            "type" : "integer"
          }
        }
      }
    }
  }
}

the valuations nested object mapping is a collection of such objects.

I would like to sort documents according to the lowerPrice ascending for 
the max date valuation in each document i.e. for each document, get the 
latest valuation in the history.valuations collection according to max date, 
then project the lowerPrice value from the valuation and order by this 
value ascending.

What I have at the moment is:

{
    "from": 0,
    "size": 20,
    "sort": [{
        "history.valuations.date": {
            "order": "desc",
            "mode": "max"
        }
    }, {
        "history.valuations.lowerPrice": {
            "order": "asc"
        }
    }]
}

But I am not 100% certain that this does what I expect it to. Looking at 
the results when I run this query, it *looks *like it is working, but any 
feedback with someone better versed with more complex sorting would be 
greatly appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/e1ac4169-a66e-44ee-8dc6-f8e2f1669bad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to