I'm attempting to use the elasticsearch
service within my Kibana 7.4 plugin. The plugin works fine when using the search endpoint (I get a HTTP 200 response and search results), however the count endpoint results in a HTTP 404 (Not Found).
As I understand it, Kibana proxies searches to the elasticsearch cluster. Given I'm running a local dev server for Kibana 7.4 my searches use URLs like the following.
http://localhost:5601/fhv/s/<space name>/elasticsearch/my-index/_count
http://localhost:5601/fhv/s/<space name>/elasticsearch/my-index/_search
If I manually curl
the count endpoint using one of the nodes in my elasticsearch cluster, I get a response including the count of documents matching my query (as expected).
Some sample code to help demonstrate what I'm doing in my Kibana plugin:
import {
EuiSearchBar,
Query,
} from '@elastic/eui';
// onChange handler for EuiSearchBar
euiSearchBarChanged({query}: {query: Query}) {
/* es is my handle to the elasticsearch client instance.
* Passed in as a React property to my plugin's component.
* app.js lists this as a dependency for the Angular RootController --- e.g.
* `RootController($scope, $element, es) { ... }`
*/
const {es} = this.props;
const esQuery = Query.toESQuery(query);
const params = {
index: 'my-index',
body: { query: esQuery },
};
// Error handler used and specifies a 404.
es.count(params).then(
r => console.log('count results', r),
e => console.log('count error', e)
);
// Logs search results as expected
es.search<MyDocType>(params).then(
r => console.log('search results', r),
e => console.log('search error', e)
);
}