文章目录
主键查询
- 主键查询
- 查询全部数据
请求方式get 请求路径: _doc后面的为数据的id主键, 即查询主键为1的数据. http://127.0.0.1:9200/shopping/_doc/1
请求体为空 返回数据如下:
{
"_index": "shopping",
"_type": "_doc",
"_id": "1",
"_version": 3,
"_seq_no": 4,
"_primary_term": 1,
"found": true,
"_source": {
"title": "小米手机",
"category": "小米",
"images": "http://xiaomi.com",
"price": 3999.00
}
}
如果查询一个不存在的id的数据, 例如如下查询id为666的数据, 那么found为false.
用_search 请求url: http://127.0.0.1:9200/shopping/_search
查询shopping索引下的全部数据 请求方式为get 结果如下: took为耗费的毫秒 hits.total.value 代表一共命中了五条数据.
{
"took": 53,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 5,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "shopping",
"_type": "_doc",
"_id": "ex0KPX4BPkzBbPhZJmdM",
"_score": 1.0,
"_source": {
"title": "小米手机",
"category": "小米",
"images": "http://xiaomi.com",
"price": 3999.00
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "fB0NPX4BPkzBbPhZNmcn",
"_score": 1.0,
"_source": {
"title": "小米手机",
"category": "小米",
"images": "http://xiaomi.com",
"price": 3999.00
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"title": "小米手机",
"category": "小米",
"images": "http://xiaomi.com",
"price": 3999.00
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "2",
"_score": 1.0,
"_source": {
"title": "小米手机",
"category": "小米",
"images": "http://xiaomi.com",
"price": 3999.00
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "3",
"_score": 1.0,
"_source": {
"title": "小米手机",
"category": "小米",
"images": "http://xiaomi.com",
"price": 3999.00
}
}
]
}
}