elasticsearch(三)term查询 -- 转载请注明出处

五、POST查询

然后调用下方下方的请求则是一个简单的数据查询请求:

请求方式:POST

URL:http://192.168.1.199:9200/_search?index=megacorp&type=employee

Header:Content-Type:application/json

Body:

{
	"from": 0,
	"size": 10,
	"query": {
		"term": {
			"age": {
				"value": 30,
				"boost": 1.0
			}
		}
	},
	"sort": [{
		"birthday": {
			"order": "desc"
		}
	}]
}

请求说明:

URL:_search/?index=megacorp&type=employee 分别为 {查询方式}?index={索引名称}&type={文档名称}  这里的索引名称与文档名称可以不填写,但是如果不填写则会连带其他索引和文档一起进行查询,建议填写。

Body:

{
	"from-查询的开始位置": 0,
	"size-查询结果数量": 10,
	"query-查询条件,可以不填": {
		"term-查询条件,后面会有详细说明": {
			"age-字段名": {
				"value-值": 30
			}
		}
	},
	"sort-排序": [{
		"birthday-排序字段名": {
			"order-排序方式": "desc-倒序"
		}
	}]
}

之后会获取到服务器的响应数据:

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": null,
    "hits": [
      {
        "_index": "megacorp",
        "_type": "employee",
        "_id": "1",
        "_score": null,
        "_source": {
          "first_name": "John",
          "last_name": "Smith",
          "age": 30,
          "about": "I love to go rock climbing",
          "interests": [
            "sports",
            "music"
          ],
          "birthday": "1989-02-02"
        },
        "sort": [
          602380800000
        ]
      },
      {
        "_index": "megacorp",
        "_type": "employee",
        "_id": "2",
        "_score": null,
        "_source": {
          "first_name": "Jack",
          "last_name": "Ma",
          "age": 30,
          "about": "I regret having founded alibaba",
          "interests": [
            "speech"
          ],
          "birthday": "1989-01-01"
        },
        "sort": [
          599616000000
        ]
      }
    ]
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值