【原創】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
        ]
      }
    ]
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章