“This is the fifth day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

Recently in the ES query operation, the first time to use, inevitably some strange, take this opportunity to see how ES is to create a similar to the database of the library table, first of all, the environment will not say here, we can first look up

http://localhost:9200/_search
Copy the code

Can we use it to find out what our ES has so far, or can we use the head plugin to do a compound query to find all of our data

Then we have to create our index, similar to mysql library, executive put request http://localhost:9200/Stu, so you can create Stu (library),

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "Stu"
}
Copy the code

We can get request execution http://localhost:9200/Stu/\_search to query the index under all of the data;

And then we can perform the put operation field information of http://localhost:9200/Stu/\_mappings to create tables

For example, let’s create the name and account of Stu

{
  "properties": {
    "name": {
      "type": "keyword"
     
    },
    "account": {
      "type": "long"
    }
  }
}
Copy the code

When “acknowledged”: true is returned, our table structure has been created, and we are ready to insert data

http://localhost:9200/Stu/\_doc/

{    "name":"xm",    "account":"12345"}
Copy the code

So now we’re inserting a piece of data, and the corresponding ID is randomly generated, so if we don’t want a random ID, we can specify it

http://localhost:9200/Stu/\_doc/111, so that you can generate an ID is 111 data, is very simple, insert the data is a post request, don’t mixed up.

If you want to delete a certain item, you can directly append the corresponding ID to the end of the address. This is their CRUD operation. When we query and insert data, pay attention to the case of data. If it’s just for testing, the simpler the test data the better, it saves a lot of trouble,