Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query by width/height or area of a geo-shape #54218

Closed
thomasneirynck opened this issue Mar 25, 2020 · 4 comments
Closed

Query by width/height or area of a geo-shape #54218

thomasneirynck opened this issue Mar 25, 2020 · 4 comments
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)

Comments

@thomasneirynck
Copy link
Contributor

thomasneirynck commented Mar 25, 2020

When running a _search for individual documents, it would be useful if ES could filter out documents where its geo_shape are smaller than a given size. (e.g. ideally by width/height in webmercator meters, but lat/lon delta could work as well).

The reason for this is that often times a client issues an ES-query in order to display the shapes at a given scale. If that scale is small enough (ie. zoomed out), features smaller than a pixel do not need to be included.

Including in the search-result documents that the recipient then will filter out, adds noise to the ES-response. These unnecessary documents also count to the index.max_result_window search limit, potentially hiding less relevant results.

This would be relevant for the Kibana Maps application, since it performs scale-based queries. This is especially relevant for vector-tiling of ES search-results (elastic/kibana#58519). When features are too small, they will be omitted from the tile anyway.

@giladgal @nknize @alexfrancoeur

@matriv matriv added the :Analytics/Geo Indexing, search aggregations of geo points and shapes label Apr 2, 2020
@elasticmachine
Copy link
Collaborator

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

@giladgal
Copy link
Contributor

giladgal commented Apr 6, 2020

The ask makes sense to me. It might be useful to include it in a query that gets all shapes that are bigger than a certain minimum threshold and within given geo bounds.

@rjernst rjernst added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label May 4, 2020
@nknize
Copy link
Contributor

nknize commented Jun 29, 2020

This was discussed in the full stack geo meeting. One way to do this would be to have something in Lucene akin to term vectors but for spatial geometries. At index time we compute the area, perimeter, etc of tessellated triangles and store them in a spatial term vector. Having this granularity would make it easier for us to compute things like area overlap, or geometric clipping, as we would be doing this on the individual triangle.

A shorter / "easier" solution might be to offer a geo_attribute enrichment processor that computes and stores this information in a geo_attribute object field.

@iverase
Copy link
Contributor

iverase commented May 27, 2021

With the introduction of painless support for geo_shape fields on #72886, this can now be achieved by using runtime fields. For example:


GET /example/_search
{
  "size": 10,
  "fields": [
    "width",
    "heigth"
  ],
  "runtime_mappings": {
    "width": {
      "script": """
         GeoBoundingBox bbox = doc['location'].getBoundingBox();
         emit(bbox.bottomRight().lon - bbox.topLeft().lon);
       """,
      "type": "double"
    },
    "heigth": {
      "script": """
         GeoBoundingBox bbox = doc['location'].getBoundingBox();
         emit(bbox.topLeft().lat - bbox.bottomRight().lat);
       """,
      "type": "double"
    }
  },
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "width": {
              "lte": 1
            }
          }
        },
        {
          "range": {
            "heigth": {
              "gte": 1
            }
          }
        }
      ]
    }
  }
}

The computation of distances is left to the user as that can be done in several ways.

@iverase iverase closed this as completed Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)
Projects
None yet
Development

No branches or pull requests

7 participants