elastic / elasticsearch

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

Encode field attributes as predicates #48864

Open not-napoleon opened 5 years ago

not-napoleon commented 5 years ago

Currently, the aggregations framework uses instanceof operations in many places to figure out what type of values we are getting. For example:

        if (indexFieldData instanceof IndexOrdinalsFieldData) {
            dataSource = new ValuesSource.Bytes.WithOrdinals.FieldData((IndexOrdinalsFieldData) indexFieldData);
        } else {
            dataSource = new ValuesSource.Bytes.FieldData(indexFieldData);
        }

(https://github.com/elastic/elasticsearch/blob/4a66cfc9686d282123659a96a3acbe1404aacdd9/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java#L353-L357)

As part of our effort to get away from hard coding type information in the core aggregations framework, we'd like to explore replacing these with predicates on the Field Data classes. For example, the above case could use a hasOrdinals() predicate instead of the instanceof check.

elasticmachine commented 5 years ago

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

elasticmachine commented 5 years ago

Pinging @elastic/es-analytics-geo (:Analytics/Aggregations)

iverase commented 4 years ago

@not-napoleon This seems to have been mostly dealt with the value source refactoring, does it make sense to have it opened or we can close it now?

not-napoleon commented 4 years ago

@iverase I didn't actually address either the specific case quoted in this ticket, or the general behavior, when I did the refactor. I just moved where we do it. The code block quoted above is now found in CoreValuesSourceType: https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/search/aggregations/support/CoreValuesSourceType.java#L119-L123

So, I vote to keep this open for now.

nik9000 commented 3 years ago

I think I just merged a hasOrdinals method. We don't use it in all the places though.

nik9000 commented 3 years ago

Ah, but that this instanceof is what gets us to my hasOrdinals in the first place.

not-napoleon commented 3 years ago

Yeah, we've made a lot of progress getting rid of instanceofs around the various ValuesSource classes. This ticket is more about the level above that, where we're selecting which ValuesSource subclass to build based on the IndexFieldData &c.

GrayFox1 commented 3 years ago

I am interested to pick this Issue, can i start to work on this?

not-napoleon commented 3 years ago

@GrayFox1 This is a pretty tricky and involved refactoring that touches a lot of the code. I would not suggest this as a starting point for contributing to Elasticsearch. If you're interested in getting some experience contributing to projects, might I suggest taking a look at our good first issue list: https://github.com/elastic/elasticsearch/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22

elasticsearchmachine commented 1 year ago

Pinging @elastic/es-analytics-geo (Team:Analytics)