appbaseio / mirage

:art: GUI for simplifying Elasticsearch Query DSL
http://opensource.appbase.io/mirage
Other
2.21k stars 125 forks source link

Add support for geo distance query #8

Closed siddharthlatest closed 7 years ago

siddharthlatest commented 8 years ago

Implement support for Geo Distance Query.

Prerequisites

The code structure will resemble the files in this path - https://github.com/appbaseio/mirage/tree/dev/app/build/singlequery/queries.

There should be two files created: geodistance.query.ts and geodistance.query.spec.ts.

Before PR

metagrover commented 7 years ago

Hey guys, I need some input with this issue.

I am getting query_parsing_exception - "failed to find geo_point field [pin.location]" when I try to run the query. I am able to generate the query of the format:

{
  "query": {
    "bool": {
      "filter": [
        {
          "geo_distance": {
            "distance": "200km",
            "pin.location": {
              "lat": "40",
              "lon": "-70"
            }
          }
        }
      ]
    }
  }
}

I had to list geo_distance under string in queryList (to check whether I'm able to generate the query of the desired format), since ES is not able to detect the Geo Point type.

Can you suggest a solution to this?

farhan687 commented 7 years ago

What is the datatype of location field? it should be geo_point, otherwise geo query will fail.

metagrover commented 7 years ago

Yeah about that, do you mean:

Specifying @Input() selectedField: geo_point; in the component and adding mappings in ES?

farhan687 commented 7 years ago

No no I am not asking about typescript datatype. I am asking about es mapping datatype.

Pin.location should have geo_point datatype of es mapping.

You should add Geo_point: ['geo_distance'] in ananlyzed, non_analyzed of queryList.

Where geo_point is datatype and geo_distance is query name.

metagrover commented 7 years ago

Yes, I've already done that, but it seems ES is not able to determine the type of the field. It is undefined.

farhan687 commented 7 years ago

Then you need to pick a new field and add geo_point mapping for that.

metagrover commented 7 years ago

I've tried that, but I think I am missing something. Type of the field is still undefined.

screen shot 2016-10-12 at 6 01 30 pm

How should I add the geo_point mapping for this field (pin)?

siddharthlatest commented 7 years ago

@metagrover ES field type needs to be defined (via mappings), Elasticsearch can't auto-infer it as geo-point. Since mappings are also immutable starting v2.0, you should define it for a new field. https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html

siddharthlatest commented 7 years ago

Merged in https://github.com/appbaseio/mirage/commit/f10cae3d681050c705cf662aa006860a78cf0040.