We are using Google distance matrix api and getting different response when using address versus coordinates for the exact same address.
When using address we don't get any information about the
borough/postal town, we only get the municipality (higher level).
WITH ADDRESS
`https://maps.googleapis.com/maps/api/distancematrix/json?
origins=Urban Hjärnes väg 18,168 58,BROMMA&destinations=Hantverkarg 67-
69,112 92,STOCKHOLM&mode=walking&language=sv-SE&key
{
"destination_addresses" : [ "Hantverkargatan 67, 112 31 Stockholm,
Sverige" ],
"origin_addresses" : [ "Urban Hjärnes väg, Stockholm, Sverige" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "8,0 km",
"value" : 7970
},
"duration" : {
"text" : "1 tim 41 min",
"value" : 6031
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
`
WITH COORDINATES
`https://maps.googleapis.com/maps/api/distancematrix/json?
units=metric&origins=59.351563, 17.922239&destinations=Hantverkarg%2067-
69,112%2092,STOCKHOLM&key=
{
"destination_addresses" : [ "Hantverkargatan 67, 112 31 Stockholm, Sweden" ],
"origin_addresses" : **[ "Urban Hjärnes väg 18, 168 58 Bromma, Sweden" ]**
,
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "7.6 km",
"value" : 7627
},
"duration" : {
"text" : "14 mins",
"value" : 824
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}`
Even when we search with the address we want
"origin_addresses" : [ "Urban Hjärnes väg 18, 168 58 Bromma, Sweden" ]
instead of
"origin_addresses" : [ "Urban Hjärnes väg, Stockholm, Sverige" ], which is not complete
I was able to replicate the issue using the ff addresses:
Correct results: "Urban Hjärnes väg 18, 168 58 Bromma, Sweden"
Urban Hjärnes väg 18
168 58 Bromma
Sweden
Incorrect results: "Urban Hjärnes väg 18,168 58 Bromma, Sweden"
Urban Hjärnes väg
Stockholm
Sweden
Notice that you can have the expected results when querying the address with proper spaces between the street number "18," and postal code "168 58". So as a workaround, you can use this sample request:
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Urban+Hjärnes+väg+18,+168+58+Bromma,+Sweden&destinations=Hantverkarg+67-69,+112+92+STOCKHOLM&mode=walking&language=sv-SE&key=API_KEY
Which correctly returns the expected address:
{
destination_addresses: [
"Hantverkargatan 67, 112 31 Stockholm, Sverige"
],
origin_addresses: [
"Urban Hjärnes väg 18, 168 58 Bromma, Sverige"
],
rows: [
{
elements: [
{
distance: {
text: "8,0 km",
value: 7976
},
duration: {
text: "1 tim 41 min",
value: 6036
},
status: "OK"
}
]
}
],
status: "OK"
}
You can also then file this issue in Google's Public Issue Tracker for their engineering team to further investigate.
Hope this helps!
Related
PRODUCT 1
"attributes_list" : {
"src1" : [
{
"aname" : "Manufacturer Standard Lead Time",
"avalue" : "16 Weeks"
},
{
"aname" : "Color",
"avalue" : "red"
},
{
"aname" : "Detailed Description",
"avalue" : "Pre-Biased Bipolar
},
{
"aname" : "DC Current Gain (hFE) (Min) # Ic, Vce",
"avalue" : "100 # 10mA, 5V"
},
{
"aname" : "Transistor Type",
"avalue" : "2 NPN - Pre-Biased (Dual)"
},
{
"aname" : "Mounting Type",
"avalue" : "Surface Mount"
}
]
}
PRODUCT 2-------------
"attributes_list" : {
"src1" : [
{
"aname" : "Lead Time",
"avalue" : "16 Weeks"
},
{
"aname" : "Color",
"avalue" : "green"
},
{
"aname" : "Description",
"avalue" : "Pre-Biased Bipolar
},
{
"aname" : "DC Current Gain (hFE) ",
"avalue" : "100 # 10mA, 5V"
},
{
"aname" : "Transistor",
"avalue" : "2 NPN - Pre-Biased (Dual)"
},
{
"aname" : "Type",
"avalue" : "Surface Mount"
}
]
}
The question is
How can i get all the colors (avalues) by key.
like:
aggs
Colors
Red
doc_count 10
Green
doc_count 5
Simple is
We need to get all the colors by key.
We have tried different aggs queries on avalue but all are getting all the avalues. We need just to get all the avalue:colors [red,green etc ] by aname:color.
Below is the code I am using:
"_source" : {
"name" : "hn name",
"user_id" : 553,
"email_id" : "ns#gmail.com",
"lres_id" : "",
"hres_id" : "hn image",
"followers" : 0,
"following" : 1,
"mentors" : 2,
"mentees" : 2,
"basic_info" : "hn developer",
"birth_date" : 1448451985397,
"charge_price" : 3000,
"org" : "mnc pvt ltd",
"located_in" : "Noidasec51 ",
"position" : "jjunior ava developer",
"requests" : 0,
"exp" : 5,
"video_bio_lres" : "hn test lres url",
"video_bio_hres" : "hn hres url",
"ratings" : [ {
"rating" : 1,
"ratedByUserId" : 777
}, {
"rating" : 1,
"ratedByUserId" : 555
} ],
"avg_rating" : 0.0,
"status" : 0,
"expertises" : [ 3345, 1234, 2345 ],
"blocked_users" : [ ]
}
In the Following Code, I want to delete rating ratedByUserId 555 only.But Some How I am unable for doing so.
How to do it?
its works for me:-
curl -XPOST 'localhost:9200/mentorz/users/555/_update' -d
'{" script":"ctx._source.ratings.remove(ratings)",
"params":{
"ratings":{
"rating":1,
"ratedByUserId":555
}
}
}'
I am using the Autocomplete API to get results 'biased' for current location with the following request:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=kuli&types=(regions)&key=[KEY]
The API returns the following response:
{
"predictions" : [
{
"description" : "Kulim Kedah Malaysia",
...
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Kuliyapitiya, North Western Province, Sri Lanka",
...
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Kulithalai, Tamil Nadu, India",
...
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Kuligów, Poland",
...
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Kulin, Western Australia, Australia",
...
"types" : [ "locality", "political", "geocode" ]
}
],
"status" : "OK"
}
As you can see above, the response does not bias for location. The doc says that the IP Address is taken into account when returning "near" locations. But from the response, the Indian locations are not returned first over others (The request IP address is Indian).
Even, when I pass location parameter with lat,long, as:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=kuli&types=(regions)&location=lat,long&key=[KEY]
still the Indian results are not prioritized over other response.
How do I make the API return location 'biased' over IP address or location coordinates? Thank you for your time.
Add components to your url: &components=country:IN
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=kuli&components=country:IN&types=(regions)&location=lat,long&key=[KEY]
My program is trying to determine the City, state, and country based on some text, for example "New york yankee stadium" I want to get New york city, NY, USA. I am using Google places API to do this. According to the documentations, the API should return a list of address component https://developers.google.com/places/web-service/details. However, right now its only returning formatted address "1 E 161st St, Bronx, NY 10451, United States".
here is my web service url
https://maps.googleapis.com/maps/api/place/textsearch/json?key=MY_KEY&query=new%20york%20yankee%20stadium
Anyone familiar with google places API that can let me know if I am not writting the right query or parameter?
{
"html_attributions" : [],
"results" : [
{
"formatted_address" : "1 E 161st St, Bronx, NY 10451, United States",
"geometry" : {
"location" : {
"lat" : 40.82964260000001,
"lng" : -73.9261745
},
"viewport" : {
"northeast" : {
"lat" : 40.83279975,
"lng" : -73.92236575000001
},
"southwest" : {
"lat" : 40.82643674999999,
"lng" : -73.93052034999999
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "3d78036d61d35f48650bda737226432b57d82511",
"name" : "Yankee Stadium",
"opening_hours" : {
"open_now" : true,
"weekday_text" : []
},
"photos" : [
{
"height" : 540,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/101696810905045719819/photos\"\u003eYankee Stadium\u003c/a\u003e"
],
"photo_reference" : "CoQBdwAAAIxmCLrNS_XZ2FcJqVvRVtBUlNYMBVTVKppOWBu7sICj2q70cqJARBoJlTcZpydbMTzURKWWMVJhYpVCqsnia5pjmDhjvjsTirrEnAc6gvmRYKuUwgewB9Re--FulXzXZ5DY3P9fkwIwuc4U9BJVbqHD5O-N6SbbHcqn4XHUj_OdEhCoNPZ3kiNJhxOCGdYG5O4DGhTqVfUjdq7JzasqYATvQxkL1-H3xg",
"width" : 1242
}
],
"place_id" : "ChIJcWnnWiz0wokRCB6aVdnDQEk",
"rating" : 4.4,
"reference" : "CmRRAAAA5dHiw1YmLxW60_jITBZjMiUs48L4aVUqlPnPDpN_ySa7rw8kPp04WWk0qf8mG-kkMFSNzh39lP0YwfynW54tLcY4s_EYbAPvNWTMe6wXHm_FJiVbI0Lfenyxz4yOTzunEhDgI64EWoXkQe9k45y6qP3-GhSVSdCMPPZA3joFbnYGV-bqo2e0lw",
"types" : [ "stadium", "point_of_interest", "establishment" ]
}
],
"status" : "OK"
}
Its a two step process, first search and get the place_id from google places search service,
use the returned place_id and pass it with another call to receive the individual address components,
https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJcWnnWiz0wokRCB6aVdnDQEk&key=
{"html_attributions": [],
"result": {
"address_components": [
{
"long_name": "1",
"short_name": "1",
"types": [
"street_number"
]
},
{
"long_name": "East 161st Street",
"short_name": "E 161st St",
"types": [
"route"
]
},
{
"long_name": "Concourse",
"short_name": "Concourse",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Bronx",
"short_name": "Bronx",
"types": [
"sublocality_level_1",
"sublocality",
"political"
]
},
{
"long_name": "Bronx County",
"short_name": "Bronx County",
"types": [
"administrative_area_level_2",
"political"
]
},
Please, observe:
MongoDB shell version: 2.4.1
connecting to: test
> use dummy
switched to db dummy
> db.invoices.find({'items.nameTags': /^z/}, {_id: 1}).explain()
{
"cursor" : "BtreeCursor items.nameTags_1_created_1_special_1__id_1_items.qty_1_items.total_1 multi",
"isMultiKey" : true,
"n" : 55849,
"nscannedObjects" : 223568,
"nscanned" : 223568,
"nscannedObjectsAllPlans" : 223568,
"nscannedAllPlans" : 223568,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 86,
"nChunkSkips" : 0,
"millis" : 88864,
"indexBounds" : {
"items.nameTags" : [
[
"z",
"{"
],
[
/^z/,
/^z/
]
],
"created" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
"special" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
"_id" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
"items.qty" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
"items.total" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
]
},
"server" : "IL-Mark-LT:27017"
}
>
Here is the definition of the index:
> db.system.indexes.find({name : 'items.nameTags_1_created_1_special_1__id_1_items.qty_1_items.total_1'}).pretty()
{
"v" : 1,
"key" : {
"items.nameTags" : 1,
"created" : 1,
"special" : 1,
"_id" : 1,
"items.qty" : 1,
"items.total" : 1
},
"ns" : "dummy.invoices",
"name" : "items.nameTags_1_created_1_special_1__id_1_items.qty_1_items.total_1"
}
>
Finally, here is an example invoice document (with just 2 items):
> db.invoices.findOne({itemCount: 2})
{
"_id" : "85923",
"customer" : "Wgtd Fm 91",
"businessNo" : "314227928",
"billTo_name" : "Wgtd Fm 91",
"billTo_addressLine1" : "3839 Ross Street",
"billTo_addressLine2" : "Kingston, ON",
"billTo_postalCode" : "K7L 4V4",
"purchaseOrderNo" : "boi",
"terms" : "COD",
"shipDate" : "2013-07-10",
"shipVia" : "Moses Transportation Inc.",
"rep" : "Snowhite",
"items" : [
{
"qty" : 4,
"name" : "CA 7789",
"desc" : "3 pc. Coffee Table set (Silver)",
"price" : 222.3,
"total" : 889.2,
"nameTags" : [
"ca 7789",
"a 7789",
" 7789",
"7789",
"789",
"89",
"9"
],
"descTags" : [
"3",
"pc",
"c",
"coffee",
"offee",
"ffee",
"fee",
"ee",
"e",
"table",
"able",
"ble",
"le",
"e",
"set",
"et",
"t",
"silver",
"ilver",
"lver",
"ver",
"er",
"r"
]
},
{
"qty" : 4,
"name" : "QP 8681",
"desc" : "Ottoman Bed",
"price" : 1179.1,
"total" : 4716.4,
"nameTags" : [
"qp 8681",
"p 8681",
" 8681",
"8681",
"681",
"81",
"1"
],
"descTags" : [
"ottoman",
"ttoman",
"toman",
"oman",
"man",
"an",
"n",
"bed",
"ed",
"d"
]
}
],
"itemCount" : 2,
"discount" : "10%",
"delivery" : 250,
"hstPercents" : 13,
"subTotal" : 5605.6,
"totalBeforeHST" : 5295.04,
"total" : 5983.4,
"totalDiscount" : 560.56,
"hst" : 688.36,
"modified" : "2012-10-08",
"created" : "2014-06-25",
"version" : 0
}
>
My problem is that mongodb does not use index only according to the aforementioned explain() output. Why? After all I only request the _id field, which is part of the index.
In general, I feel that I am doing something very wrong. My invoices collection has 65,000 invoices with the total of 3,291,092 items. It took almost 89 seconds to explain() the query.
What am I doing wrong?
You are using arrays and subdocuments. Covered Indexes dont work with either of these.
From the mongo docs:
An index cannot cover a query if:
any of the indexed fields in any of the documents in the collection includes an array. If an indexed field is an array, the index becomes a multi-key index index and cannot support a covered query.
any of the indexed fields are fields in subdocuments. To index fields in subdocuments, use dot notation. For example, consider a collection users with documents of the following form:
http://docs.mongodb.org/manual/tutorial/create-indexes-to-support-queries/