1, 简单查询, 查询books索引下的全部信息
POST /books/_search
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
{
"_index": "books",
"_type": "it",
"_id": "2dtQGGUBNmgQz3Wn9pp4",
"_score": 1,
"_source": {
"bookId": 3,
"bookName": "演员的自我修养",
"author": "周星驰",
"publishDate": "2018-08-08"
}
},
{
"_index": "books",
"_type": "it",
"_id": "2",
"_score": 1,
"_source": {
"bookId": 2,
"bookName": "Mysql",
"author": "Liudehua",
"publishDate": "2018-01-12"
}
},
{
"_index": "books",
"_type": "it",
"_id": "1",
"_score": 1,
"_source": {
"bookId": 1,
"bookName": "PHP",
"publishDate": "2018-01-12"
}
}
]
}
}
2, 简单条件查询
PUT books/it/_search
查询条件: bookName是php的
{
"query":{
"term":{
"bookName":"php"
}
}
}
查询结果:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.5193239,
"hits": [
{
"_index": "books",
"_type": "it",
"_id": "29tWGGUBNmgQz3WnOJo7",
"_score": 0.5193239,
"_source": {
"bookId": 5,
"bookName": "PHP是世界上最好的语言",
"publishDate": "2018-01-01"
}
},
{
"_index": "books",
"_type": "it",
"_id": "2ttVGGUBNmgQz3Wn35oo",
"_score": 0.2876821,
"_source": {
"bookId": 4,
"bookName": "PHP从入门到放弃",
"publishDate": "2018-01-01"
}
},
{
"_index": "books",
"_type": "it",
"_id": "1",
"_score": 0.2876821,
"_source": {
"bookId": 1,
"bookName": "PHP",
"publishDate": "2018-01-12"
}
}
]
}
}
3, 分页查询:
POST /books/it/_search
请求参数:
{
"from":0,"size":2,
"query":{
"term":{
"bookName":"php"
}
}
}
查询结果:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.5193239,
"hits": [
{
"_index": "books",
"_type": "it",
"_id": "29tWGGUBNmgQz3WnOJo7",
"_score": 0.5193239,
"_source": {
"bookId": 5,
"bookName": "PHP是世界上最好的语言",
"publishDate": "2018-01-01"
}
},
{
"_index": "books",
"_type": "it",
"_id": "2ttVGGUBNmgQz3Wn35oo",
"_score": 0.2876821,
"_source": {
"bookId": 4,
"bookName": "PHP从入门到放弃",
"publishDate": "2018-01-01"
}
}
]
}
}
4, 排序
POST books/it/_search
{
"sort":{
"bookId":{"order":"asc"},
"author":{"order":"desc"}
}
}