---
title: EntitySearchQuery
source: https://docs.newrelic.com/docs/new-relic-solutions/build-nr-ui/sdk-component/query-and-storage/EntitySearchQuery
---

Search for entities.

### Usage

```jsx
import { EntitySearchQuery } from 'nr1'
```

### Examples

#### Declarative query

```jsx
function render() {
  const filters = [
    {
      type: EntitySearchQuery.FILTER_TYPE.TAG,
      value: { key: "environment", value: "production" },
    },
  ];

  return (
    <EntitySearchQuery filters={filters}>
      {({ loading, error, data, fetchMore }) => {
        if (loading) {
          return <Spinner />;
        }

        if (error) {
          return "Error!";
        }

        return (
          <List
            items={data.entities}
            rowCount={data.count}
            rowHeight={20}
            onLoadMore={fetchMore}
          >
            {({ item }) => <ListItem key={item.guid}>{item.name}</ListItem>}
          </List>
        );
      }}
    </EntitySearchQuery>
  );
}
```

#### Fetch with sorting criteria

```jsx
<EntitySearchQuery
  entityDomain="APM"
  sortType={[EntitySearchQuery.SORT_TYPE.ALERT_SEVERITY]}
>
  {({ data, error, fetchMore }) => {
    if (error) {
      return "Error!";
    }

    return (
      <List
        items={data.entities}
        rowCount={data.count}
        rowHeight={20}
        onLoadMore={fetchMore}
      >
        {({ item }) => <ListItem key={item.guid}>{item.name}</ListItem>}
      </List>
    );
  }}
</EntitySearchQuery>
```

#### Imperative query

```js
EntitySearchQuery.query({
  filters: [
    {
      type: EntitySearchQuery.FILTER_TYPE.TAG,
      value: { key: 'environment', value: 'production' },
    },
  ],
}).then(({ data }) => console.log(data));
```

#### Fetch more results using imperative query

```js
const filters = [
  {
    type: EntitySearchQuery.FILTER_TYPE.TAG,
    value: { key: 'environment', value: 'production' },
  },
];

const firstPage = await EntitySearchQuery.query({ filters });

console.log('First page data', firstPage.data);

const cursor = firstPage.data.nextCursor;
const secondPage = await EntitySearchQuery.query({ cursor, filters });

console.log('Second page data', secondPage.data);

// NOTE: To fetch multiple page results consecutively, use EntitySearchQuery
// component's fetchMore approach.
```

### Props

| `children` function                        | Render prop function as a child.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `entityDomain` string                      | Domain of the entities you want to query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `entityFragmentExtension` object           | GraphQL fragment document parsed into an AST by `graphql-tag`.The Query components return the most commonly used fields available on an entity. You can use this prop when you want to request additional fields for the entities returned by your query.The fragment should be named `EntityFragmentExtension` and apply to the `EntityOutline` type. ````js const entityFragmentExtension = ngql`   fragment EntityFragmentExtension on EntityOutline {     indexedAt     guid   } `; ```  ````                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `entityGuids` string\[]                    | GUID of the entities to query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `entityType` string                        | Type of the entities you want to query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `fetchPolicyType` enum                     | Allows you to specify how you want your query to interact with the cached data. - `CACHE_AND_NETWORK`: The query returns your initial data from the cache if available. However, regardless of whether or not the full data is in your cache, the query always makes a request using your network interface and returns the updated data. This option is not available when using the static `query()` method of the component. - `CACHE_FIRST`: The query makes a request using your network interface **only** if the data for your query is not already in the cache. - `CACHE_ONLY`: The query **never** makes a request using your network interface. Instead it returns the data available in the cache. If the data for your query does not exist in the cache, then an error is thrown. - `NETWORK_ONLY`: The query **never** returns your initial data from the cache. Instead it **always** makes a request using your network interface. - `NO_CACHE`: The query **never** returns your initial data from the cache. Instead it **always** makes a request using your network interface. Unlike the `NETWORK_ONLY` policy, it does not write any data to the cache after the query completes. EntitySearchQuery.FETCH_POLICY_TYPE.CACHE_AND_NETWORK, EntitySearchQuery.FETCH_POLICY_TYPE.CACHE_FIRST, EntitySearchQuery.FETCH_POLICY_TYPE.CACHE_ONLY, EntitySearchQuery.FETCH_POLICY_TYPE.NETWORK_ONLY, EntitySearchQuery.FETCH_POLICY_TYPE.NO_CACHE, |
| `filters` string\|(shape\|shape\|shape)\[] | Filters used to narrow down the entities.This is an array of filters, and there are 3 possible filters: - SearchQueryFilter: `Object<type: string = "searchQuery", value: string>` - EntityTypeFilter: `Object<type: string = "entityType", Object<domain: string, type: string>>` - TagFilter: `Object<type: string = "tag", Object<key: string, value: string>>` ```js const filters = [   {     type: 'searchQuery',     value: 'foo',   },   {     type: 'entityType',     value: { domain: 'APM', type: 'APPLICATION' },   },   {     type: 'tag',     value: { key: 'environment', value: 'production' },   },   {     type: 'tag',     value: { key: 'team', value: 'bar' },   }, ]; ```                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `includeCount` boolean                     | If `true`, the query response includes the total count of entities for each domain and type.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `includeResults` boolean                   | If `true`, the query response includes entities.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `includeSummaryMetrics` boolean            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `includeTags` boolean                      | If `true`, the returned entities include their tags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `limit` number                             | Pagination, number of entities to fetch for on each page.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `name` string                              | Name or partial name of the entities to query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `pollInterval` number                      | Interval in milliseconds to poll for new data. Set to zero to avoid any kind of regular polling.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `skip` boolean                             | When set to `true`, the query will be skipped entirely from rendering.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `sortBy` DEPRECATED                        | > #### ⚠️ DUE NOVEMBER 1ST, 2023 > > The sortBy is deprecated, use sortType instead                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `sortType` enum\[]                         | Array of criteras used to sort the entity search results. EntitySearchQuery.SORT_TYPE.ALERT_SEVERITY, EntitySearchQuery.SORT_TYPE.DOMAIN, EntitySearchQuery.SORT_TYPE.MOST_RELEVANT, EntitySearchQuery.SORT_TYPE.NAME, EntitySearchQuery.SORT_TYPE.REPORTING, EntitySearchQuery.SORT_TYPE.TYPE,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |

### Methods

### `EntitySearchQuery.query`

### Type definitions
