Elasticsearch shows points outside boundingbox nest

I use Bounding Box in elasticsearch but, I get points outside of box ,it never shows points inside this box. this my Code:

 var response = _elasticClient.Search<ElasticSearchModel>(
                     s => s.From((model.CurrentPage-1)*model.PageSize)
                     .Size(model.PageSize)
                     .Query(query => query.Bool(b => b
                     .Filter(f=>f.QueryString(d => d.Query(model.Keyword)))))
                     .Query(query => query.Bool(b => b
                     .Filter(filter => filter
           
                    .GeoBoundingBox(g => g
                    .Boost(1.1)
                    .Name("Location")
                    .Field(p => p.Location)
                    .BoundingBox(c => c
                    .TopLeft(model.Points.X2, model.Points.Y2)
                    .BottomRight(model.Points.X1, model.Points.Y1)  
                     )
                    .ValidationMethod(GeoValidationMethod.Strict)
                    .Type(GeoExecution.Indexed)
                    )
                    )
              

                        )
               ));

Hi,

Could you provide the following information:

  • Version of Elasticsearch

  • Mapping example

  • Bounding box example

  • Point example that you are expecting to be inside of the bounding box and it is not getting match.

1)Version of Elasticsearch is 6.5, my amozon elasticsearch also 6.5.
2) Mapping

{

* "state": "open",
* "settings": {
  * "index": {
    * "creation_date": "1561656440210",
    * "number_of_shards": "5",
    * "number_of_replicas": "1",
    * "uuid": "-KYZLyItRbSGaCcZ2y4wag",
    * "version": {
      * "created": "6050499"},
    * "provided_name": "honadonz"}},
* "mappings": {
  * "elasticsearchmodel": {
    * "properties": {
      * "buildingPhotos": {
        * "properties": {
          * "title": {
            * "type": "text",
            * "fields": {
              * "keyword": {
                * "ignore_above": 256,
                * "type": "keyword"}}}}},
      * "address": {
        * "type": "text",
        * "fields": {
          * "keyword": {
            * "ignore_above": 256,
            * "type": "keyword"}}},
      * "buildingRooms": {
        * "properties": {
          * "roomCount": {
            * "type": "integer"},
          * "roomType": {
            * "type": "integer"}}},
      * "moneyType": {
        * "type": "text",
        * "fields": {
          * "keyword": {
            * "ignore_above": 256,
            * "type": "keyword"}}},
      * "description": {
        * "type": "text",
        * "fields": {
          * "keyword": {
            * "ignore_above": 256,
            * "type": "keyword"}}},
      * "totalRooms": {
        * "type": "integer"},
      * "createdDate": {
        * "type": "date"},
      * "size": {
        * "type": "double"},
      * "sizeName": {
        * "type": "text",
        * "fields": {
          * "keyword": {
            * "ignore_above": 256,
            * "type": "keyword"}}},
      * "buildAction": {
        * "type": "text",
        * "fields": {
          * "keyword": {
            * "ignore_above": 256,
            * "type": "keyword"}}},
      * "ownerPrice": {
        * "type": "double"},
      * "buildType": {
        * "type": "text",
        * "fields": {
          * "keyword": {
            * "ignore_above": 256,
            * "type": "keyword"}}},
      * "location": {
        * "type": "geo_point"},
      * "id": {
        * "type": "integer"},
      * "buildTitle": {
        * "type": "text",
        * "fields": {
          * "keyword": {
            * "ignore_above": 256,
            * "type": "keyword"}}}}}},
* "aliases": [ ],
* "primary_terms": {
  * "0": 1,
  * "1": 1,
  * "2": 1,
  * "3": 1,
  * "4": 1},
* "in_sync_allocations": {
  * "0": [
    * "R4A0rGIETFipJHArGG9MPQ"
,    * "2eVySrycSWSShjyt6vSX5w"],
  * "1": [
    * "2ytj0PYXT5WN34TdDR058w"
,    * "SNWs5bZUSlqt5d0MAoakMA"],
  * "2": [
    * "zW2g7W2vSVCtXmTsWH6xtA"
,    * "CDsaaTjVTPijiABC61TzpA"],
  * "3": [
    * "ufemNrnGSTy1KH1kPegMrA"
,    * "eYxzTCLPRY-JNGgITEseGQ"],
  * "4": [
    * "CifuWl5tT06qwOeVTej6nA"
,    * "ZaPWMzwxRA-PMeEYLnkMcA"]}

}

20

Not related to your question but

BTW did you look at Elastic Cloud: Hosted Elasticsearch, Hosted Search | Elastic and AWS Marketplace: Elastic Cloud (Elasticsearch Service) ?

Cloud by elastic is one way to have access to all features, all managed by us. Think about what is there yet like Security, Monitoring, Reporting, SQL, Canvas, APM, Logs UI, Infra UI, SIEM, Maps UI and what is coming next :slight_smile: ...

for my startup amazon is suitable, it is free for 12 month. How can I fix my problem?

Let's wait for @Ignacio_Vera to answer. :slight_smile:

The plot shows us the issue but it does not help trying to debug / understand what is going oon. We would need the actual values of the bounding box (TopLeft and BottomRight points) and the value of one of the points ( Lat and Lon).

BottomRight: x1=41.22388330186993 x2:69.13315496215819
TopLeft : y1:41.375029128357596 y2:69.34704503784178

Point inside bouding box:

* "location": {
  * "lat": 41.3096311599291,
  * "lon": 69.24346804618834},

It looks to me like your BottomRight is actually a BottomLeft as x1 < y1. This also makes your TopLeft a TopRight. If you correct these I suspect you will see a different result.

I changed TopLeft and BottomRight value from

                    .GeoBoundingBox(g => g
                    .Boost(1.1)
                    .Name("Location")
                    .Field(p => p.Location)
                    .BoundingBox(c => c
                    .TopLeft(model.Points.Y1, model.Points.Y2)
                    .BottomRight(model.Points.X1, model.Points.X2)  
                     )
                    )

to

                 .GeoBoundingBox(g => g
                    .Boost(1.1)
                    .Name("Location")
                    .Field(p => p.Location)
                    .BoundingBox(c => c
                    .TopLeft(model.Points.X1, model.Points.X2)
                    .BottomRight(model.Points.Y1, model.Points.Y2)  
                     )
                    )

But I got error

"Invalid NEST response built from a unsuccessful low level call on POST: /honadonz/elasticsearchmodel/_search?typed_keys=true\n# Audit trail of this API call:\n - [1] BadResponse: Node: https://search-honadon-aws-s2kjvr4n5ncradyspmbopyjw2e.us-east-2.es.amazonaws.com/ Took: 00:00:00.2333030\n# OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 400 from: POST /honadonz/elasticsearchmodel/_search?typed_keys=true. ServerError: Type: illegal_argument_exception Reason: "top is below bottom corner: 41.239679247732255 vs. 41.36792753714556"\n# Request:\r\n{"from":0,"query":{"bool":{"filter":[{"geo_bounding_box":{"boost":1.1,"_name":"Location","location":{"bottom_right":{"lat":41.367927537145562,"lon":69.350024455166078},"top_left":{"lat":41.239679247732255,"lon":69.141140046615661}}}}]}},"size":100}\n# Response:\r\n{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"top is below bottom corner: 41.239679247732255 vs. 41.36792753714556"}],"type":"illegal_argument_exception","reason":"top is below bottom corner: 41.239679247732255 vs. 41.36792753714556"},"status":400}\n"

You Right, I get value from openlayers BottomLeft, TopRight,
What you suggest , how can I fix problem?

I think the right answer is as following:

.GeoBoundingBox(g => g
                    .Boost(1.1)
                    .Name("Location")
                    .Field(p => p.Location)
                    .BoundingBox(c => c
                    .TopLeft(model.Points.y1, model.Points.X2) 
                    .BottomRight(model.Points.X1, model.Points.Y2) 
                     )
                    )

thank you, now it's working correctly.

BTW, Now I have bad Experience with aws, I don't recommend to anybody to use aws elasticsearch it cost more money even with this ads,

I dont know about how much total cost elastic cloud service per month , i used calculator, but i didn't understood total price per month.

Regardless of the service you use the cost will typically depend on what size cluster you need and in which region you want to deploy. Without any information about this it is hard for anyone to help.

1 Like

I think that the price calculator gives you a price per hour, right?

YES, it gives a price per hour.

Then take that times 24 times 365 and you have the cost per year. The cost per month will depend on the number of days in the month.

If i have limit , and my elastic uses more than limit, cloud get extra money for it or cloud blocks requests more than limit

You are paying for the size of the cluster, not number of documents or requests. There are typically some additional costs related to traffic in and out of the cluster and snapshots (depends on your usage), but I would expect that to be small compared to the base cost. Naturally there is a limit to the amount of traffic and data a cluster of a specific size can handle.

AWS get money for extra requests, and I got letter in end of month that i should pay extra money for that. I have question about https://cloud.elastic.co/, it works like AWS?