elastic_client icon indicating copy to clipboard operation
elastic_client copied to clipboard

Write example

Open leech001 opened this issue 5 years ago • 2 comments

Please write example on (elastic_client) DART from my python code.

q = {
  "query": {
    "multi_match": {
      "query":    "John*",
      "fields": "*"
    }
  }
}

res = es.search(index="kpmi_etalon_obj", body=q)
print("Got %d Hits:" % res['hits']['total']['value'])
for hit in res['hits']['hits']:
    print(hit['_source']['etalonId'])

leech001 avatar Apr 08 '20 16:04 leech001

final _transport = ConsoleHttpTransport(Uri.parse('http://test.ru:9200/'));
    String query = '''{
      "query": {
        "multi_match": {
          "query": "John*",
          "fields": "*"
        }
      }
    }''';
final response = await _transport.send(Request('POST', ['kpmi_etalon_obj','_search'], bodyText: query));
    if (response.statusCode == 200) {
      var result = response.bodyAsMap;
      countElements = result['hits']['total']['value'];
      _elements = result['hits']['hits'];
      _elements.forEach((element) {
      final record = ElementList(
          id: element['_id'],
          title: element['_source']['project']['name'],
          );
          items.add(record); 
      });

Decided so but this is a mega perversion for your library.

leech001 avatar Apr 10 '20 13:04 leech001

Decided so but this is a mega perversion for your library.

I'm open for API changes and suggestions of improvements (also PRs are welcome!).

isoos avatar Apr 10 '20 13:04 isoos