Elasticsearch是一个适用于需要灵活过滤的场景的搜索和分析引擎。有时,我们需要检索请求的数据及其聚合信息。 在本教程中,我们将探讨如何做到这一点。
2. Elasticsearch搜索与聚合
让我们从探索Elasticsearch的聚合功能开始。
一旦我们在本地主机上运行了Elasticsearch实例,让我们创建一个名为_store-items_的索引,并在其中添加一些文档:
POST http://localhost:9200/store-items/_doc
{
"type": "Multimedia",
"name": "PC Monitor",
"price": 1000
}
...
POST http://localhost:9200/store-items/_doc
{
"type": "Pets",
"name": "Dog Toy",
"price": 10
}
大约 4 分钟