Multiple location fields


(Mario Menezes) #1

Hi,

I'm using django-haystack and ElasticSearch to index Stores.

Until now, each store had one lat,long coordinate pair; we had to change
this to represent the fact that one store can deliver products to very
different regions (disjunct) I've added up to ten locations (lat,long
pairs) to then.

When using one location field everything was working fine and I got right
results. Now, with multiple location fields, I can't get any results, not
even the previuos one, for the same user and store coordinates.

My Index is as following:

curl -XGET http://localhost:9200/stores/_mapping?pretty=True
{
"stores" : {
"modelresult" : {
"properties" : {
"django_id" : {
"type" : "string"
},
"location0" : {
"type" : "geo_point",
"store" : "yes"
},
"location1" : {
"type" : "geo_point",
"store" : "yes"
},
"location2" : {
"type" : "geo_point",
"store" : "yes"
},
"location3" : {
"type" : "geo_point",
"store" : "yes"
},
"location4" : {
"type" : "geo_point",
"store" : "yes"
},
"location5" : {
"type" : "geo_point",
"store" : "yes"
},
"location6" : {
"type" : "geo_point",
"store" : "yes"
},
"location7" : {
"type" : "geo_point",
"store" : "yes"
},
"location8" : {
"type" : "geo_point",
"store" : "yes"
},
"location9" : {
"type" : "geo_point",
"store" : "yes"
},
"text" : {
"type" : "string",
"analyzer" : "snowball",
"store" : "yes",
"term_vector" : "with_positions_offsets"
}
}
}
}
}

Then, I try to search my locations:

$ curl -XGET http://localhost:9200/stores/modelresult/_search?pretty=true
-d '{ "query" : { "match_all": {} }, "filter" : {"geo_distance" : {
"distance" : "6km", "location0" : { "lat" : -23.5, "lon" : -46.5 } } } } '
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}

If I change my index and use only one location (this mapping):
$ curl -XGET http://localhost:9200/stoes/_mapping?pretty=True
{
"stores" : {
"modelresult" : {
"properties" : {
"django_ct" : {
"type" : "string"
},
"django_id" : {
"type" : "string"
},
"id" : {
"type" : "string"
},
"location0" : {
"type" : "geo_point",
"store" : "yes"
},
"text" : {
"type" : "string",
"analyzer" : "snowball",
"store" : "yes",
"term_vector" : "with_positions_offsets"
}
}
}
}
}

Then, when I search, using the same query, I get:

$ curl -XGET http://localhost:9200/stoes/modelresult/_search?pretty=true -d
'{ "query" : { "match_all": {} }, "filter" : {"geo_distance" : {
"distance" : "6km", "location0" : { "lat" : -23.5, "lon" : -46.5 } } } } '
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "stores",
"_type" : "modelresult",
"_id" : "store.store.128",
"_score" : 1.0, "_source" : {"django_ct": "store.store", "text":
"Blah Blah", "django_id": "128", "id": "store.store.128", "location0":
"-23.5380755,-46.4663468"}
} ]
}
}

 Can anyone tells me what I doing wrong? That is, why I'm not getting 

any results for the multiple location settings. I really need this feature.

 Of course, I rebuild the index after changing the location fields 

(removing or adding them).

 Thanks in advance.

 BTW, I'm pretty new to ElasticSearch.

(system) #2