koopjs / koop-provider-elasticsearch

A provider for koop that can connect to one or more elastic search instances and turn indices/aliases into individual feature services.
Apache License 2.0
13 stars 4 forks source link

Handling statistics and object ID requests at an es level, not at a winnow level #22

Open keithfraley opened 3 years ago

keithfraley commented 3 years ago

I have done some work in the old koop es provider to handle the query string statistics request within es, so that you can a true representation of unique values (for example) in order to do this we intercept the request coming from agol and modify the request going to es.

Example below, I have not looked yet into how to do this in the new es provider

`if (query.groupByFieldsForStatistics) {
            esQuery.body.aggs = {
                "uniqueValueCount": {
                    "cardinality": {
                        "field": query.groupByFieldsForStatistics + ".keyword"
                    }
                },
                [indexConfig.index]: {
                    "terms": {
                        "field": query.groupByFieldsForStatistics + ".keyword",
                        "size": 10000
                    }
                }
            };
        }
        if (query.objectIds) {
            esQuery.body.query.bool.filter = {
                ids: {}
            };

            esQuery.body.query.bool.filter.ids.values = [query.objectIds];
   `
`var whereParser = new WhereParser();
        if (where) {
            if (where.includes("UPPER")) {
                where = where.replace(/UPPER/g, '');
            }
            if (where.includes("objectid")) {
                where = where.replace("objectid", '_id');
            }
            if (where.includes("OBJECTID")) {
                where = where.replace("OBJECTID", '_id');
            }
            var boolClause = whereParser.parseWhereClause(where, indexConfig.dateFields, indexConfig.returnFields);
            if (boolClause) {
                if (boolClause.bool) {
                    if (boolClause.bool.must) {
                        boolClause.bool.must.push({ exists: { field: indexConfig.geometryField } });
                    }
                    else {
                        boolClause.bool.must = [
                            { exists: { field: indexConfig.geometryField } }
                        ];
                    }
                    esQuery.body.query = boolClause;
                }
                else {
                    esQuery.body.query.bool.must.push(boolClause);
                }
            }

        }`
zakhtar1998 commented 2 years ago

@keithfraley were you able to setup koop successfully and view the json in the api? If so, it is possible if you can share your code or email address so i can reach out to you. Looking forward to hearing from you.