Глава 4: Освоение расширенных методов запросов в Elasticsearch: раскрытие возможностей расширенного поиска

Определение запросов в Elasticsearch: использование возможностей DSL на основе JSON для комплексных запросов

# POST /student/_doc/1001
{
"name":"zhangsan", 
"nickname":"zhangsan", 
"sex":"Male",
"age":30
}
# POST /student/_doc/1002
{
"name":"lisi", "nickname":"lisi", "sex":"男", "age":20
}
# POST /student/_doc/1003
{
"name":"wangwu", "nickname":"wangwu", "sex":"女",
"age":40
}
# POST /student/_doc/1004
{
"name":"zhangsan1", "nickname":"zhangsan1", "sex":"女",
"age":50
}
# POST /student/_doc/1005
{
"name":"zhangsan2", "nickname":"zhangsan2", "sex":"女",
"age":30
}
  1. Запрос всех документов

В Postman отправьте GET-запрос на сервер ES: http://127.0.0.1:9200/student/_search

{
  "query": {
    "match_all": {}
  }
}

In the above example, "query" represents a query object that can contain different query properties. "match_all" is a query type, such as match_all (which represents querying all documents), match, term, range, etc. {query conditions} will vary based on the query type.

Ответ сервера следующий:


{
  "took": 1116, // Query execution time in milliseconds
  "timed_out": false, // Indicates whether the query timed out
  "_shards": {
    "total": 1, // Total number of shards
    "successful": 1, // Number of successful shards
    "skipped": 0, // Number of skipped shards
    "failed": 0 // Number of failed shards
  },
  "hits": {
    "total": {
      "value": 3, // Total number of documents matching the search criteria
      "relation": "eq" // Calculation rule for the total count (eq for exact, gte for an approximation)…