elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.98k stars 24.75k forks source link

Ability to perform Nested Sort Like filtering #51818

Open f3l1xss opened 4 years ago

f3l1xss commented 4 years ago

Currently we have nested sort functionality where we are able to specify filter logic, path, sortMode (min, max, sum, avg, median).

https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html#nested-sorting

It would be wonderful if there can be similar functionality for filtering where we can specify above parameters + boolean expression to evaluate whether the doc is valid.

For Example given mapping below:

cargroup

 "mappings": {
    "properties": {
      "id":     { "type": "integer" },
      "cars":   { "type": "nested",
                            "properties": {
                                    "brand": {
                                        "type": "keyword"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                        },

and documents:

[id: 1,
cars:[{
brand: toyota,
value: 30},
{
brand: toyota,
value: 30},
{
brand: honda,
value: 30}
],
id: 2,
cars:[{
brand: toyota,
value: 30},
{
brand: toyota,
value: 50},
{
brand: honda,
value: 30}
],
id: 3,
cars:[{
brand: toyota,
value: 30},
{
brand: toyota,
value: 80},
{
brand: honda,
value: 30}
]]

I could easily search for doc which has Sum of Toyota value greater than 100 by setting filter logic as 'term: brand= toyota', path: cars, filterMode: sum, boolean expression: totalSum > 100

Theoretically, we can achieve the same thing using script query. However, I realized that in filter context https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-filter-context.html

_source is not available, only doc values which prohibit us from accessing nested fields.

elasticmachine commented 4 years ago

Pinging @elastic/es-search (:Search/Search)

f3l1xss commented 4 years ago

Hi, anybody looking into this?

f3l1xss commented 4 years ago

Hello what do you guys think about this? @jimczi @dliappis

tigra-sms commented 4 years ago

Is there any update on this issue? It would be great to have this functionality enabled. It used to work in v5.6, nested objects could be accessed via _source variable in a filter, but updating to v7 it stopped working and seems there's no way to have this done now.

f3l1xss commented 4 years ago

@MarinaRNext I have been waiting for 6 mths and there has been no response at all. So strange as this functionality seem pretty basic to me

elasticsearchmachine commented 4 months ago

Pinging @elastic/es-search (Team:Search)

elasticsearchmachine commented 3 months ago

Pinging @elastic/es-search-relevance (Team:Search Relevance)