Tuesday, June 08, 2021

Elasticsearch

I have my elasticsearch in my window services. I only start up this service when I need it.

To see all elasticsearch index in the local, open browser to
http://localhost:9200/_cat/indices?v

To view a particular index data, open browser to
http://localhost:9200/[index name]/_search

For example: my earthquakes data
http://localhost:9200/earthquakes/_search
The data is in hits.hits.

 

Use bulk function to insert multiple records.
To avoid the data duplication when inserting, apply the same _id.

    let body = earthquakes.flatMap(
        obj => [{ index: { _index: INDEX_id: obj.id } }, obj]
    );
    let results = await client.bulk({ 
        refresh: true,
        body
    });

No comments: