78 lines
1.2 KiB
Plaintext
78 lines
1.2 KiB
Plaintext
// This file is autogenerated, DO NOT EDIT
|
|
// Use `node scripts/generate-docs-examples.js` to generate the docs examples
|
|
|
|
[source, js]
|
|
----
|
|
const response = await client.indices.create({
|
|
index: "node",
|
|
mappings: {
|
|
properties: {
|
|
ip: {
|
|
type: "ip",
|
|
},
|
|
date: {
|
|
type: "date",
|
|
},
|
|
},
|
|
},
|
|
});
|
|
console.log(response);
|
|
|
|
const response1 = await client.bulk({
|
|
index: "node",
|
|
refresh: "true",
|
|
operations: [
|
|
{
|
|
index: {},
|
|
},
|
|
{
|
|
ip: "192.168.0.1",
|
|
date: "2020-01-01T01:01:01",
|
|
m: 1,
|
|
},
|
|
{
|
|
index: {},
|
|
},
|
|
{
|
|
ip: "192.168.0.1",
|
|
date: "2020-01-01T02:01:01",
|
|
m: 2,
|
|
},
|
|
{
|
|
index: {},
|
|
},
|
|
{
|
|
ip: "192.168.0.2",
|
|
date: "2020-01-01T02:01:01",
|
|
m: 3,
|
|
},
|
|
],
|
|
});
|
|
console.log(response1);
|
|
|
|
const response2 = await client.search({
|
|
index: "node",
|
|
filter_path: "aggregations",
|
|
aggs: {
|
|
ip: {
|
|
terms: {
|
|
field: "ip",
|
|
},
|
|
aggs: {
|
|
tm: {
|
|
top_metrics: {
|
|
metrics: {
|
|
field: "m",
|
|
},
|
|
sort: {
|
|
date: "desc",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
console.log(response2);
|
|
----
|