Build your own search engine Part 3

I. Introduction

Continue from the previous article Building your own search engine Part 2 : This article mainly talks about how we operate ElasticSearch, that is, how to write the simplest add, delete, modify and search commands.

2. Several concepts

In this article about building one of your own search engines,  we compare some reasons why search engines are better than relational databases in real-time querying of massive data. Here we compare some concepts of the two types of data storage.

ElasticSearch can contain multiple indexes, and each index can contain multiple types (higher versions (7.X and above) can only contain one type, and the type name is _doc. It is said that subsequent 8. removed), each type contains multiple documents, and each document contains multiple fields.

ElasticSearch data type

3. Basic operations of ElasticSearch

The ElasticSearch operation command is RestFul style, and the basic format of the request is:

METHOD http://ip:9200/<index>/<type>/[<id>]

Among them, index and type must be provided, and id is optional (ES will automatically generate it if not provided). In the following examples, we use POSTMAN to operate ES, and the Body type is set to raw+json.

1. Create an index structure

put http://118.178.233.68:9200/stock_valuation

Creating an index and setting the field type can be understood as creating a table structure, and settings set some information about the index. Sharding is set here, because we are still a single node, so it is set to 1 first. Open the head to view the index information.

2. Insert document

POST http://118.178.233.68:9200/stock_valuation/_doc

View data

3. Delete documents

delete http://118.178.233.68:9200/stock_valuation/_doc/Vsz8e34BPimbKlzBZLfY

Vsz8e34BPimbKlzBZLfY Internal ID automatically generated by ES when inserting a document.

4. Modify document content

POST http://118.178.233.68:9200/stock_valuation/_doc/V8wDfH4BPimbKlzBsbd6/_update

Note: ES actually modifies the document by first deleting the old document and then recreating the new document. Use HEAD to view the document content and you will find that _version has become 2.

5. Simple query

Note: I’m in a hurry to eat mutton pot, so I’ll write it here first!

Guess you like

Origin blog.csdn.net/2301_76787421/article/details/133411663