[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eLooker Studio can apply filters to data from community connectors, but applying filters within the connector itself can significantly enhance performance.\u003c/p\u003e\n"],["\u003cp\u003eCommunity connectors should apply all filters provided in the \u003ccode\u003egetData()\u003c/code\u003e request or none at all, and structure them with \u003ccode\u003eAND\u003c/code\u003e and \u003ccode\u003eOR\u003c/code\u003e logic as specified.\u003c/p\u003e\n"],["\u003cp\u003eIf a connector cannot apply all filters, it should return all data and indicate \u003ccode\u003efiltersApplied: false\u003c/code\u003e in the response, ensuring backward compatibility.\u003c/p\u003e\n"],["\u003cp\u003eWhen filters are successfully applied within the connector, the response should exclude \u003ccode\u003eforFilterOnly\u003c/code\u003e fields and include \u003ccode\u003efiltersApplied: true\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Filters\n\nIf a report contains [filters](https://support.google.com/looker-studio/answer/6291066) and a community connector returns unfiltered data\nfor all fields requested then Looker Studio will apply filters to the connector\nresponse. However, filters can be applied at the community connector level which\ncan significantly improve performance in some cases. Filter information is\npassed in the [getData() request object](/looker-studio/connector/reference#dimensionsfilters), and the connector can use this\ninformation to filter data before sending it back to Looker Studio.\n\nFor example, if you're connecting to a SQL database, applying the filters\ndirectly in the `WHERE` clause (B3 in diagram below) can drastically decrease\nthe number of rows returned to Looker Studio. This, in turn, limits the amount\nof data that has to be processed and sent to Looker Studio (B5).\n\n| **Note:** It's not required to apply filters, but it is recommended if you expect performance gains from applying them.\n\nRules of applying filters\n-------------------------\n\n1. Apply *all* filters, or *none* of them. See [Unsupported filters](#unsupportedfilters)\n2. Do not include [`forFilterOnly`](/looker-studio/connector/reference#forfilteronly) fields in the response.\n3. `AND` together each entry in the [`request.dimensionsFilters`](/looker-studio/connector/reference#dimensionsfilters) array.\n\n For example, for the following filter, the connector should only include\n values that have a `country` of `USA` **AND** a `source` of `Social`. \n\n {\n \"dimensionsFilters\": [\n [{\n \"fieldName\": \"country\",\n \"values\": [\"USA\"],\n \"type\": \"INCLUDE\",\n \"operator\": \"EQUALS\"\n }],\n [{\n \"fieldName\": \"source\",\n \"values\": [\"Social\"],\n \"type\": \"INCLUDE\",\n \"operator\": \"EQUALS\"\n }]\n ]\n }\n\n4. `OR` together each sub-array in the [`request.dimensionsFilters`](/looker-studio/connector/reference#dimensionsfilters) array.\n\n For example, for the following filter, the connector should only include\n values that have a `country` of `USA` **OR** a `country` of `Canada`. \n\n {\n \"dimensionsFilters\": [\n [{\n \"fieldName\": \"country\",\n \"values\": [\"Canada\"],\n \"type\": \"INCLUDE\",\n \"operator\": \"EQUALS\"\n }, {\n \"fieldName\": \"country\",\n \"values\": [\"USA\"],\n \"type\": \"INCLUDE\",\n \"operator\": \"EQUALS\"\n }]\n ]\n }\n\n| **Caution:** The difference between `OR` and `AND` is subtle. `AND` has the structure `[[1], [2]]`, whereas `OR` has the structure `[[1, 2]]`\n\nExample\n-------\n\nThe following example illustrates an end-to-end flow from the report user\ndefining filters to the community connector returning filtered data.\n\n1. The report user has configured two filters:\n\n 1. `country` is `IN_LIST` of `Canada, USA`\n 2. `source` is `IN_LIST` of `Social, Organic`\n2. The report user has configured a chart component with the `source` dimension\n and `sessions` metric\n\n3. `getData()` is executed by Looker Studio with the following request object:\n\n {\n \"fields\": [\n {\"name\": \"source\"},\n {\"name\": \"sessions\"},\n {\"name\": \"country\", \"forFilterOnly\": true}\n ],\n \"dimensionsFilters\": [\n [{\n \"fieldName\": \"country\",\n \"values\": [\"Canada\", \"USA\"],\n \"type\": \"INCLUDE\",\n \"operator\": \"IN_LIST\"\n }],\n [{\n \"fieldName\": \"source\",\n \"values\": [\"Social\", \"Organic\"],\n \"type\": \"INCLUDE\",\n \"operator\": \"IN_LIST\"\n }]\n ]\n }\n\n4. Connector responds with filtered data.\n\n For the example request, return the `source` and `sessions` where `country`\n is `\"Canada\"` or `\"USA\"` *AND* the `source` is `\"Social\"` or `\"Organic\"`.\n Set `filtersApplied` to `true` since all filters were able to be\n successfully applied.\n\n### Original data\n\n| source | sessions | country |\n|-----------|----------|---------|\n| Social | 60 | USA |\n| Social | 50 | Canada |\n| Social | 40 | UK |\n| Organic | 90 | USA |\n| Organic | 80 | Canada |\n| Organic | 70 | UK |\n| Newspaper | 30 | USA |\n| Newspaper | 20 | Canada |\n| Newspaper | 10 | UK |\n\n### Filtered data\n\n| source | sessions |\n|---------|----------|\n| Social | 60 |\n| Social | 50 |\n| Organic | 90 |\n| Organic | 80 |\n\n### `getData()` response\n\n {\n \"schema\": [\n {\"name\": \"source\", \"dataType\": \"STRING\"},\n {\"name\": \"sessions\", \"dataType\": \"NUMBER\"},\n ],\n \"rows\": [\n {\"values\": [\"Social\", 60]},\n {\"values\": [\"Social\", 50]},\n {\"values\": [\"Organic\", 90]},\n {\"values\": [\"Organic\", 80]}\n ],\n \"filtersApplied\": true\n }\n\n| **Key Point:** `response.rows[].values` does not have an entry for `country` and `filtersApplied` is set to `true`.\n\nUnsupported filters\n-------------------\n\nIf the connector cannot apply all filters in the request, no filtering should be\nperformed. Return all of the requested fields (including the `forFilterOnly`\nfields) and set the `filtersApplied` key in your response to `false`.\n| **Key Point:** This is the standard response for `getData()`. All existing connectors are backwards compatible with this change.\n\nExample: \n\n {\n \"schema\": [\n {\"name\": \"source\", \"dataType\": \"STRING\"},\n {\"name\": \"sessions\", \"dataType\": \"NUMBER\"},\n {\"name\": \"country\", \"dataType\": \"STRING\"}\n ],\n \"rows\": [\n {\"values\": [\"Social\", 60, \"USA\"]},\n {\"values\": [\"Social\", 50, \"Canada\"]},\n {\"values\": [\"Social\", 40, \"UK\"]},\n {\"values\": [\"Organic\", 90, \"USA\"]},\n {\"values\": [\"Organic\", 80, \"Canada\"]},\n {\"values\": [\"Organic\", 70, \"UK\"]},\n {\"values\": [\"Newspaper\", 30, \"USA\"]},\n {\"values\": [\"Newspaper\", 20, \"Canada\"]},\n {\"values\": [\"Newspaper\", 10, \"UK\"]},\n ],\n \"filtersApplied\": false\n }"]]