elasticsearch kibana Simple Query Explanation

  • 2021-06-29 10:57:03
  • OfStack

1. Simple CRUD operation

1. Add


PUT /index/type/id
{
 "json data "
}

2. Query


GET /index/type/id

3. Modification


POST /index/type/id/_update
{
 "doc": {
  "FIELD": " value "
 }
}

4. Delete


DELETE /index/type/id

2. Search

Searches can be grouped into six categories

1. query string search 2. query DSL 3. query filter 4. full-text search 5. phrase search 6. highlight search

1. query string search

Search all: GET supplier/user/_search


{
 "took": 2,
 "timed_out": false,
 "_shards": {
  "total": 5,
  "successful": 5,
  "failed": 0
 },
 "hits": {
  "total": 3,
  "max_score": 1,
  "hits": [
   {
    "_index": "supplier",
    "_type": "user",
    "_id": "2",
    "_score": 1,
    "_source": {
     "name": "lisi",
     "age": 26,
     "address": "bei jing tong zhou",
     "price": 10000,
     "dept": [
      "kaifabu"
     ]
    }
   },
   {
    "_index": "supplier",
    "_type": "user",
    "_id": "1",
    "_score": 1,
    "_source": {
     "name": "zhangsan",
     "age": 30,
     "address": "bei jing chang chun jie",
     "price": 15000,
     "dept": [
      "kaifabu",
      "yanfabu"
     ]
    }
   },
   {
    "_index": "supplier",
    "_type": "user",
    "_id": "3",
    "_score": 1,
    "_source": {
     "name": "wangwu",
     "age": 26,
     "address": "bei jing tong zhou yun he ming zhu",
     "price": 13000,
     "dept": [
      "kaifabu"
     ]
    }
   }
  ]
 }
}

took: It took several milliseconds

timed_out: Timeout or not, there is no

_shards: The data is split into five fragments, so for search requests, all primary shard (or one of its replica shards)

hits.total: Number of query results, 3 documents

hits.max_score: score means document's matching score for an search correlation, the more relevant, the more matched, and the higher the score

hits.hits: Contains detailed data for document matching the search

2. query DSL

Query all


GET supplier/user/_search
{
 "query": { "match_all": {} }
}

Query All and Sort


GET suppluer/user/_search
{
 "query": {
  "match_all": {}
 }
 , "sort": [
  {
   "price": {
    "order": "desc"
   }
  }
 ]
}

Paging Query


GET supplier/user/_search
{
 "query": { "match_all": {} },
 "from": 1,
 "size": 1
}

Specify field to query for display


GET supplier/user/_search
{
 "query": { "match_all": {} },
 "_source": ["name", "price"]
}

3. query filter

Search name for'lisi'and price greater than 1500


GET supplier/user/_search
{
  "query" : {
    "bool" : {
      "must" : {
        "match" : {
          "name" : "lisi" 
        }
      },
      "filter" : {
        "range" : {
          "price" : { "gt" : 1500} 
        }
      }
    }
  }
}

4. full-text search (Full Text Retrieval)

address, this field is first split up to create an inverted index


GET /index/type/id
0

5. phrase search (Phrase Search)

In contrast to full-text retrieval, full-text retrieval breaks up the input search string, removes 11 matches from the inverted index, and returns as a result if any of the disassembled words can be matched

phrase search, a search string that requires input, must contain exactly one-size-one in the specified field text before it can be counted as a match to be returned as a result


GET /index/type/id
1

6. highlight search (Highlight Search Results)


GET /index/type/id
2

summary


Related articles: