Seeing which part of the result is matching the query in Python SDK `get_urns_by_filter` with GraphQL API详

Original Slack Thread

When using the python sdk to search urns with get_urns_by_filter, is it possible to see which part of the result is matching the query, like when searching with the datahub ui?

Hey there! :wave:

<@U06TM7M40RK> Can you help with the questions in this thread?

:information_source: Please continue to tag RunLLM (e.g <@U06TM7M40RK>) to have it continue generating responses!

To address your question about using the get_urns_by_filter method in the Python SDK to see which part of the result is matching the query, the current implementation of get_urns_by_filter does not provide detailed information about which part of the result matches the query. This method is designed to return URNs that match the specified filters but does not include metadata about the matching fields.

However, you can achieve more detailed search results, including information about which fields matched the query, by using the GraphQL API. The GraphQL API allows for more advanced queries and can return detailed search results, including matched fields.

Here is an example of how you can use the GraphQL API to perform a search and get detailed information about the matching fields:

import requests

query = """
{
  search(input: {type: DATASET, query: "example_query_text", start: 0, count: 10}) {
    start
    count
    total
    searchResults {
      entity {
        urn
        type
        ... on Dataset {
          name
          platform {
            name
          }
        }
      }
      matchedFields {
        name
        value
      }
    }
  }
}
"""

url = "https://your-datahub-instance/api/graphql"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer your-access-token"
}

response = requests.post(url, json={'query': query}, headers=headers)
print(response.json())

This query will return detailed search results, including the matchedFields for each entity, which indicates which fields matched the query.

Would you like more details on how to set up and use the GraphQL API for this purpose?

Sources:

Hi :slight_smile: ! Did this interaction resolve your issue or do you still require assistance ?

Please tag @ RunLLM if you still need further assistance !

Or tag @Datahub Community Support if you require a person to take a look :slight_smile:

Hope this helps ! ><