# GeoQuery doesn't work

**URL:** <https://discuss.elastic.co/t/geoquery-doesnt-work/197738>\
**Category:** Elasticsearch\
**Created:** [September 2, 2019, 9:50pm UTC](https://discuss.elastic.co/t/geoquery-doesnt-work/197738 "2019-09-02T21:50:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego\_Lucas\_Martinez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diego_lucas_martinez/32/41161_2.png) [@Diego\_Lucas\_Martinez](https://discuss.elastic.co/u/Diego_Lucas_Martinez)\
**Post date:** [September 2, 2019, 9:50pm UTC](https://discuss.elastic.co/t/geoquery-doesnt-work/197738/1 "2019-09-02T21:50:42Z")

</div>

I am trying to do a GeoQuery with Nest but it dosen't work both on kibana and NEST with .net.

**Here is the NEST Query**

```
GeoDistanceQuery a = new GeoDistanceQuery
            {
                Boost = 1.1,
                Name = "named_query",
                Field = new Field("location"),
                DistanceType = GeoDistanceType.Arc,
                Location = new Nest.GeoLocation(0, 0),
                Distance = "2000m",
                ValidationMethod = GeoValidationMethod.IgnoreMalformed
                
                
                
            };
            
            mustClauses.Add(a);
            var searchRequest = new SearchRequest<User>("people")
            {
                Size = 10,
                From = 0,
                Query = new BoolQuery
                {                 
                    Should = mustClauses
                    
                    
                }
            };

```

And here is the objects what i am triying to find, location (\*) is the important field:

```
    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : 1,
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "people",
            "_type" : "user",
            "_id" : "6574f01b-f9ac-4cbb-bce8-7f072eded1ff",
            "_score" : 1.0,
            "_source" : {
              "userDates" : {
                "id" : null,
                "address1" : null,
                "address2" : null,
                "city" : null,
                "country" : null,
                "name" : null,
                "postalCode" : null,
                "state" : null,
                "surname" : null,
                "phone" : null,
                "score" : 0.0,
                **"location" : {**
 **"lat" : 0.0,**
 **"lon" : 0.0**
 **},**
                "lat" : 0.0,
                "lon" : 0.0,
                "profileImg" : null,
                "suscribed" : true,
                "personalInfo" : null,
                "user" : null
              },
              "admin" : false,
              "status" : false,
              "rememberMe" : false,
              "password" : null,
              "token" : null,
              "tokenExpiration" : "0001-01-01T00:00:00",
              "email" : "javote95@gmail.com",
              "userKnowledges" : [
                {
                  "knowledgesId" : "b4e66abc-7dfd-40af-89f9-58af57311be7",
                  "knowledges" : {
                    "id" : "b4e66abc-7dfd-40af-89f9-58af57311be7",
                    "value" : "Arquitectura",
                    "explanation" : "3973",
                    "userKnowledges" : [],
                    "jobKnowledges" : null
                  },
                  "userId" : "6574f01b-f9ac-4cbb-bce8-7f072eded1ff"
                },
                {
                  "knowledgesId" : "f989d840-734c-47c2-b9cf-57f68a0b5c1e",
                  "knowledges" : {
                    "id" : "f989d840-734c-47c2-b9cf-57f68a0b5c1e",
                    "value" : "Arquímedes",
                    "explanation" : "2752",
                    "userKnowledges" : [],
                    "jobKnowledges" : null
                  },
                  "userId" : "6574f01b-f9ac-4cbb-bce8-7f072eded1ff"
                }
              ],
              "jobsWorker" : [],
              "jobPreWorker" : [],
              "jobsCreator" : [],
              "suscription" : null,
              "notifications" : [],
              "id" : "6574f01b-f9ac-4cbb-bce8-7f072eded1ff",
              "userName" : "javote95@gmail.com",
              "normalizedUserName" : "JAVOTE95@GMAIL.COM",
              "normalizedEmail" : "JAVOTE95@GMAIL.COM",
              "emailConfirmed" : false,
              "passwordHash" : "AQAAAAEAACcQAAAAEFm8eSLL3zsy5ZfiEUxqOlemiXH1+FvM0ytR6RCD/fd3gNNactWRKJRgnfgUfjwRMQ==",
              "securityStamp" : "X2I22W2IFYXT4Y6Q4WTTY3CQFONWSWZD",
              "concurrencyStamp" : "525ea3e1-f190-435b-ab4e-1ee7e30154cb",
              "phoneNumber" : null,
              "phoneNumberConfirmed" : false,
              "twoFactorEnabled" : false,
              "lockoutEnd" : null,
              "lockoutEnabled" : true,
              "accessFailedCount" : 0
            }
          }
        ]
      }
    }

```

**And here is the query on Kibana:**

```
POST /people/_search?typed_keys=true
{"from":0,"query":{"bool":{"should":[{"geo_distance":{"_name":"named_query","boost":1.1,"validation_method":"ignore_malformed","distance":"20000m","distance_type":"arc","location":{"lat":0.0,"lon":0.0}}}]}},"size":10}

```

**Result:**

```
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : []
  }
}

```

I would really appreciate a hand. I am a bit desperate. Thx u guys, regards from Spain slight\_smile:

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [September 3, 2019, 6:07am UTC](https://discuss.elastic.co/t/geoquery-doesnt-work/197738/2 "2019-09-03T06:07:36Z")

</div>

Could you share the mapping of your index? I see in the document you share with us that the `location` attribute is under `userDates` object.

---

<div class="post-metadata">

**Author:** ![Diego\_Lucas\_Martinez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diego_lucas_martinez/32/41161_2.png) [@Diego\_Lucas\_Martinez](https://discuss.elastic.co/u/Diego_Lucas_Martinez)\
**Post date:** [September 3, 2019, 2:03pm UTC](https://discuss.elastic.co/t/geoquery-doesnt-work/197738/3 "2019-09-03T14:03:00Z")

</div>

Hi Ignacio!thx u for you answer, here is my mapping, is a bit big but the interesting point is the "location", i had to cut the object because is very big and it doesn't accept so much characters:

```
{
  "people" : {
    "mappings" : {
      "user" : {
        "properties" : {
          "accessFailedCount" : {
            "type" : "integer"
          },
          "admin" : {
            "type" : "boolean"
          },
        
          "location" : {
            "type" : "geo_point"
          },       
              "lat" : {
                "type" : "double"
              },
              "location" : {
                "properties" : {
                  "lat" : {
                    "type" : "double"
                  },
                  "lon" : {
                    "type" : "double"
                  }
                }
              },
              "lon" : {
                "type" : "double"
              },
```

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [September 4, 2019, 6:30am UTC](https://discuss.elastic.co/t/geoquery-doesnt-work/197738/4 "2019-09-04T06:30:20Z")

</div>

There is something I don't understand, your mapping and your example document seem to be different.

Your example doc:

```auto
"userDates" : {
                "id" : null,
                "address1" : null,
                "address2" : null,
                "city" : null,
                "country" : null,
                "name" : null,
                "postalCode" : null,
                "state" : null,
                "surname" : null,
                "phone" : null,
                "score" : 0.0,
                **"location" : {**
 **"lat" : 0.0,**
 **"lon" : 0.0**
** },

```

But in the mapping I do not see any object called `userDates`. Could you double check why there is this discrepancy?

---

<div class="post-metadata">

**Author:** ![Diego\_Lucas\_Martinez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diego_lucas_martinez/32/41161_2.png) [@Diego\_Lucas\_Martinez](https://discuss.elastic.co/u/Diego_Lucas_Martinez)\
**Post date:** [September 4, 2019, 5:37pm UTC](https://discuss.elastic.co/t/geoquery-doesnt-work/197738/5 "2019-09-04T17:37:17Z")

</div>

Here is the Object UserDates and its mapping, this is a object inside of the object User, but answer befor i cut it the entire mappings because my objects user has lots of objects inside, like UserDates, UserKnowledges etc...

```
 "userDates" : {
                "properties" : {
                  "address1" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "address2" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "city" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "country" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "id" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "lat" : {
                    "type" : "double"
                  },
                  "location" : {
                    "properties" : {
                      "lat" : {
                        "type" : "double"
                      },
                      "lon" : {
                        "type" : "double"
                      }
                    }
                  },
                  "lon" : {
                    "type" : "double"
                  },
                  "name" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "personalInfo" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "phone" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "postalCode" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "profileImg" : {
                    "type" : "short"
                  },
                  "score" : {
                    "type" : "double"
                  },
                  "state" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "surname" : {
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "suscribed" : {
                    "type" : "boolean"
                  },
                  "user" : {
                    "type" : "object"
                  }
                }
              },
```

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [September 6, 2019, 4:09am UTC](https://discuss.elastic.co/t/geoquery-doesnt-work/197738/6 "2019-09-06T04:09:10Z")

</div>

> [@Diego\_Lucas\_Martinez](#):
>
> "location" : { "properties" : { "lat" : { "type" : "double" }, "lon" : { "type" : "double" } } },

This should be mapped as a `geo_point` data type.

What may be happening is that a document is indexed into the index, _before_ the mapping of your document type is created in the index. When this happens, the mapping for a type is _inferred_ from the first document it sees. In your case here, because `location` should be mapped as a `geo_point`, we want to [explicitly specify the mapping](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/mapping.html) before any documents are indexed.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 4, 2019, 4:14am UTC](https://discuss.elastic.co/t/geoquery-doesnt-work/197738/7 "2019-10-04T04:14:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
