GeoQuery doesn't work

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:

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.

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"
              },

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

Your example doc:

"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?

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"
                  }
                }
              },

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 before any documents are indexed.

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