Add, delete, and alter indexes for ElasticSearch7

Delete the document

Select * from xu where id = 1;



Now to delete the document, the syntax is simple:



So that’s deleting it,



2. Query all document data

Add two new data:



To view all documents, run the following command:



Now you can see all the data in the document. If there is too much data in the document, ElasticSearch will also display the data in pages:



There is a “_score” field in the data list for sorting, and the larger the value of “_score” is, the higher the rank is. The principle is realized according to the TF-IDF scoring algorithm I mentioned in several previous articles. At present, no sorting rule is specified when we query, so the default value of “_score” is 1.



As with relational databases, ElasticSearch supports paging queries using the “FROM” and “size” fields:



This completes the paging query:



Creation of structured indexes

The indexes created in the previous article were unstructured, such as these:



A structured index specifies the structure of the index, including the specified field type:



After the index is created, it is less likely to produce dirty data than unstructured indexes:



The previous unstructured index looked like this.



After creating structured indexes, you can add data:



Because we specified the type when we created the structured index, we will get an error if the field type does not match:





The odd thing is that the following does not return an error, and even if you add double quotes, you will still recognize the integer type:



The next section introduces the complex query operations for ElasticSearch7.