搜索数据
既然我们已经大致了解了基础知识,那么让我们试着研究一个更现实的数据集。我准备了一个客户银行账户信息的虚构JSON文档样本。每个文档都有以下结构:
{
"account_number": 0,
"balance": 16623,
"firstname": "Bradshaw",
"lastname": "Mckenzie",
"age": 29,
"gender": "F",
"address": "244 Columbus Place",
"employer": "Euron",
"email": "bradshawmckenzie@euron.com",
"city": "Hobucken",
"state": "CO"
}
出于好奇,此数据是使用www.json-generator.com/生成的,因此请忽略数据的实际值和语义,因为这些都是随机生成的。
加载示例数据集
您可以从这里下载示例数据集(accounts.json)。将其提取到当前目录,然后按如下方式将其加载到集群中:
curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_bulk?pretty&refresh" --data-binary "@accounts.json"
curl "localhost:9200/_cat/indices?v"
注意:如上实际操作是使用_bulk进行批量穿件索引,实际可执行命令如下:
POST /bank/_bulk?pretty
{"index":{"_id":"1"}}
{"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
.......
查询响应:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open bank l7sSYV2cQXmu6_4rJWVIww 5 1 1000 0 128.6kb 128.6kb
这意味着我们刚刚成功地将1000个文档批量索引到银行索引中。