Sorting on nested elements

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Sorting on nested elements

Blake McBride

I have a query that I want to be sorted by specific nested elements.  I get back the correct result with no errors, but it is not sorted.  I feel confident that it is something to do with the "sort" element of my query.  Really kind of lost.  Sure appreciate some help.

Mapping:

{
  "components": {
    mappings: {
      component: {
        properties: {
          classifications: { type: "string", index: "not_analyzed" },
          componentProperties: {
            type: "nested",
            properties: {
              name: { type: "string" },
              numericValue: { type: "double" },
              stringValue: { type: "string" },
              units: { type: "string" }
            }
          },
          name: { type: "string" },
          position: { type: "long" }
        }
      }
    }
  }
}


Query:

curl -s -XGET 'http://localhost:9200/components/_search' -d '{
  from: 0,
  size: 20,
  query: {
    bool: {
      must: [
        {
          match_phrase_prefix: { classifications: "passive_components/resistors/single_components/" }
        }
      ]
    }
  },
  sort: [
    {
      "componentProperties.numericValue": {
        order: "asc",
        nested_filter: { term: { "componentProperties.name": "Resistance" } }
      }
    }
  ]
}
'


So, I want it sorted by the numericValue element when that element is associated with name=Resistance.

Example single document:


      {
        _index: "components",
        _type: "component",
        _id: "391a635c-ee56-46d1-9d9e-343d89b323c5",
        _score: null,
        _source: {
          name: "R 1206 1.1 0.333W 5% Thick Film",
          classifications: "passive_components/resistors/single_components/",
          componentProperties: [
            {
              name: "Resistance",
              stringValue: "1.1",
              numericValue: 1.1,
              units: "ohm"
            },
            {
              name: "Cp",
              stringValue: "0.07e-12",
              numericValue: 7e-14,
              units: "F"
            },
            { name: "Octopart mpn", stringValue: "ESR18EZPJ1R1" },
            {
              name: "Ls",
              stringValue: "0.95e-9",
              numericValue: 9.5e-10,
              units: "H"
            }
          ],
          position: 12
        },
        sort: ["Infinity"]
      }

Sure appreciate some help!

Thanks.

Blake McBride

--
Please update your bookmarks! We moved to https://discuss.elastic.co/
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9b327396-c525-4aef-95bc-ace863593046%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Sorting on nested elements

Divya Devaraj
This post has NOT been accepted by the mailing list yet.
I am facing a similar issue now. Were you able to fix the sorting with nested fields ?