使用flutter开发跨平台Application.i无法从elasticSearch获取数据
final transport = ConsoleHttpTransport(Uri.parse('http://localhost:9200/'));
final client = elastic.Client(transport);
final result = await client.search('indexname', '', elastic.Query.term(''),source: true);
print(result);
请帮助我。
答案 0 :(得分:-1)
_loadItems(_page) async {
List _elements =[];
final _transport = ConsoleHttpTransport(Uri.parse('http://test.ru:9200/'));
final _client = elastic.Client(_transport);
final _result = await _client.search(
'kpmi_etalon_obj', '',
// elastic.Query.matchAll(),
// source: true,
elastic.Query.term('project.code', ['001', '002', '003', '004', '005', '006', '007', '008', '009']),
source: ['shortName','project.name','stateWork'],
offset: _page*20,
limit: 20
);
final _resultFin = _result.toMap();
countElements = _resultFin['totalCount'];
_elements = _resultFin['hits'];
_elements.forEach((element) {
final record = ElementList(
id: element['_id'],
title: element['doc']['project']['name'],
subtitle: element['doc']['shortName'],
leading: element['doc']['stateWork'],
// trailing: element['doc']['cost'].toString()
);
items.add(record);
});
setState(() {});
_transport.close();
}
有关更多示例,请访问https://github.com/isoos/elastic_client/tree/master/example