I'm trying to use the new Places Insights API to count bars in my city, but I'm getting unexpected results. I want to count places that are primarily bars but NOT restaurants that happen to have a bar. My current query looks like this:
{
"insights": ["INSIGHT_COUNT"],
"filter": {
"locationFilter": {
"region": {
"place": "places/ChIJIQBpAG2ahYAR_6128GcTUEo"
}
},
"typeFilter": {
"includedTypes": ["bar"]
}
}
}
This returns way too many results because it's including restaurants that have "bar" as a secondary type. How can I modify my query to only get places that are primarily bars?
To get only places that are primarily bars (not restaurants with bars), you should use includedPrimaryTypes
instead of includedTypes
. Here's why:
includedTypes
matches against both primary and secondary types, so it will return any place that has "bar" in either categoryincludedPrimaryTypes
only matches against the primary type, so it will return only places where "bar" is the main classificationHere's the corrected query:
json
{
"insights": ["INSIGHT_COUNT"],
"filter": {
"locationFilter": {
"region": {
"place": "places/ChIJIQBpAG2ahYAR_6128GcTUEo"
}
},
"typeFilter": {
"includedPrimaryTypes": ["bar"]
}
}
}
For even more precise filtering, you could explicitly exclude restaurants:
json
{
"insights": ["INSIGHT_COUNT"],
"filter": {
"locationFilter": {
"region": {
"place": "places/ChIJIQBpAG2ahYAR_6128GcTUEo"
}
},
"typeFilter": {
"includedPrimaryTypes": ["bar"],
"excludedTypes": ["restaurant"]
}
}
}