Create indexes

First, we opened our Kibana tool to execute ES commands. ES commands are Restful, that is, PUT, GET, POST, and DELETE. You can think of ES as a database, where test1 is the database name, user is the table name, and 1 is the field

PUT /test1/user/1 {"name": "love Java programmer ", "age": 22}Copy the code

Get the value

GET /test1 GET the data of a document GET /test1/user/1 GET a field of the data of a document GET /user_index/_doc/1? GET /user_index/_doc/1/_source Queries all information about the specified index. GET /user_index/_search queries test_index data and sorts the data in descending order by age

GET /test_index/_search
{
  "query": {"match_all": {}},
  "sort": [
    {
      "age": {
        "order": "desc"
      }
    }
  ]
}
Copy the code

Query test_index data descending and paging

GET /test_index/_search
{
  "query": {"match_all": {}},
  "sort": [
    {
      "age": {
        "order": "desc"
      }
    }
  ],
  "from": 0,
  "size": 2
}
Copy the code

Fuzzy match word segmentation query

GET/test_index / _search {" query ": {" match" : {" name ":" * * "}}}Copy the code

Range queries

GET /test_index/_search
{
  "query": {
    "bool": {
      "must": { "match_all": {} },
      "filter": {
        "range": {
          "age": {
            "gte": 15,
            "lte": 25
          }
        }
      }
    }
  }
}
Copy the code

Term Accurate matching query

GET /test_index/_search
{
    "query": {
        "term": {
            "age": "18"
        }
    }
}
Copy the code

Queries documents with the specified prefix

GET/test_index / _search {" query ": {" prefix" : {" name ":" zhang "}}}Copy the code

Support wildcard query

GET/test_index / _search {" query ": {" wildcard" : {" name ":" greetings * "}}}Copy the code

Match will split the keyword when matching, and then search according to the word segmentation match, while term will directly search the keyword. General fuzzy lookups use match, while exact lookups use term

Modify the value

Change the age to 21

POST /test1/user/1/_update
{
  "doc": {
    "age": 21
  }
}
Copy the code

Delete the value

DELETE document 1 DELETE /test1/user/1 DELETE index test1 DELETE /test1