How to make queries to elasticsearch from client side of kibana plugin


I am trying to query elasticsearch indices from client side of kibana plugin.

I was unable to find any native kibana plugin components which can readily enable me to create a client with which I can make request to elasticsearch with all the Privileges and roles of user.

Currently I resorted to making a fetch request like this

fetch ("/api/console/proxy?path=indexName%2F_search&method=GET", requestOptions)

in app.tsx or other child modules of app.tsx in public/components folders of generated kibana plugin ( generated using plugin generator in scripts)

Which works fine in local development environment but, when deployed in prod gives me 404 for normal and works fine for superuser or admin users.

Setup info:

The whole setup is on version 7.9.1,

For building the plugin we are using 7.x branch of kibana


Hi, you'll want to add a dependency for the data plugin in your app, and use its services to fetch data from ES:

Hi @tsullivan,

Tried using the data plugin, while creating a custom search query like mentioned below:

    const [indexPattern, setIndexPattern] = useState<IndexPattern | null>();

    useEffect(() => {
      const setDefaultIndexPattern = async () => {
          const defaultIndexPattern = await data.indexPatterns.getDefault();

    }, [data]);

    const query = {
      query: {
        "bool": {
          "must": [
              "match": {
                "name": "first"
      language: 'dsl'

    const aggs = [
        id: 'count', 
        type: 'cardinality', 
        params: { 
          field: indexPattern.getFieldByName("_id").name 

    const aggsDsl =,aggs).toDsl()

    const searchSource = await;
    const searchResponse = await searchSource
      .setField('index', indexPattern)
      .setField('query', query)
      .setField('aggs', aggsDsl)

but query is not getting reflected in the response, only aggs is applied properly to the search API call.

setField says it requires Query | undefined type object but there is no function in data plugin which will build and return a Query type object.

and the same goes for the filters as well, there is no function in data plugin via which we can create Filter type object, though when I run data.query.filterManager.getFilters() I get the exsiting applied Filters.

How can I create Custom Filter and Query objects??


This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

Hi, there is an excellent example plugin in the Kibana source repo to give a live example of what you are trying to do:

You can import interfaces from the Data plugin, and use the plugin API to create a req object as seen here:

Then you create a subscription to the search results with and handle the response data in the callback of the subscription as seen here:

If you intend to search using Elasticsearch DSL syntax, you do not need a custom search strategy.