Hi.
I'm trying to develop a plugin that queries data in Elasticsearch every 5s and shows the data.
I made it perfectly in version 7.11.1.
However, after I upgraded my Elasticsearch nodes and kibana to 7.17.0, I'm struggling to upgrade my plugin.
I used data plugin to use timefilter and refresh interval.
Here's my previous code.
let searchSource: ISearchSource;
let indexPattern: IndexPattern | undefined;
// Create searchSource and find index patterns.
const call = async () => {
searchSource = await data.search.searchSource.create();
[indexPattern] = await data.indexPatterns.find(Config.indexPattern);
};
call();
// Use React hooks to manage state.
// const [hits, setHits] = useState<Array<Record<string, any>>>();
const [color, setColor] = useState<string>(Config.color.default);
// Use useEffect function to manage the lifecycle.
useEffect(() => {
data.query.timefilter.timefilter.setRefreshInterval({
pause: false,
value: Config.refreshIntervalValue,
});
// autoRefreshFetch$ makes a stream every {refreshInterval.value} milliseconds.
const autoRefreshFetch$ = data.query.timefilter.timefilter.getAutoRefreshFetch$();
// Query object must have language property with either 'lucene' or 'kuery'.
// Lucene represents QueryDSL, the other does ESQuery.
autoRefreshFetch$.subscribe(() => {
searchSource
.setField('index', indexPattern)
.setField('size', 1)
.setField('sort', { '@timestamp': SortDirection.desc })
.fetch()
.then((response) => {
console.log(JSON.stringify(response));
});
});
// This return phrase is called when the element is unmounted from DOM.
return () => {
data.query.timefilter.timefilter.setRefreshInterval({ pause: true });
};
}, []);
It worked perfectly in 7.11.1 , but not in 7.17.0.
I found that fetch() function had been deprecated, and getAutoRefreshFetch$() function had been changed also.
I have no idea how to use a subscription of fetch$() inside of the subscription of autoRefreshFetch$.
Please help me with it. Thank you.