Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of adding, deleting, changing and searching Elasticsearch document Index

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the "Elasticsearch document index add, delete, change and search method" related knowledge, editor through the actual case to show you the operation process, the operation method is simple and fast, practical, I hope that this "Elasticsearch document index modification method" article can help you solve the problem.

Interface idempotency

0 interface idempotency: mathematical concept, multiple requests, equivalent to one request

Get,put,delete are all idempotent interfaces.

Post has the problem of idempotency.

The front end is very fast. If you click twice, two orders will be generated.

When the user visits the new page (submitting an order)-"API returns a unique id, submits the order, brings a unique id, and the backend determines whether the unique id has been used -" No, create an order

The problems you encounter in the project and how to solve (project harvest) place orders, often repeat orders, click quickly, idempotent problems, how to solve

Inverted index

1.es introduces 10 points

two。 Installation

-jdk: java development environment

Download the corresponding version of es on the official website, decompress it, and start elasticsearch.bat in the bin directory.

Two clients (kibana: official, sending requests, data statistics, presentation, elasticsearch-head: written by third parties in node)

Kibana corresponds to the es version. Launch directly under the bin path.

Elasticsearch-head needs to install node environment, npm install-"npm run start"

Kibana profile configuration (copy, address port of kibana listener, any name, address to connect to es)

Modify es configuration: allow cross-domain (browser's same origin policy), cors: cross-domain resource sharing, achieve cross-domain resource sharing

Inverted index of es (extended reading .md)

Segment the article and index each word

3 Index Operation # Index Operation-"Database Operation -" add, delete, modify Query # 1 New index: PUT lqz2 # lqz2 is the index name {"settings": {"index": {"number_of_shards": 5, "number_of_replicas": 1}} # 2 query index GET lqz2/_settings returns the result {"lqz2": {"settings": {"index": {"creation_date": "1588822389842" "number_of_shards": "1", "number_of_replicas": "1", "uuid": "NBXIeVdHQ26vCuPn8_6uew", "version": {"created": "7050099"} "provided_name": "lqz2"} # 3 Update index PUT lqz2/_settings {"number_of_replicas": 2} # 4 Delete lqz2 index DELETE lqz24 document basic addition, deletion, query and modification # 1 New document POST lqz2/_doc/1 {"title": "Dream of Red Mansions", "price": 12, "publish_addr": {"province": "Heilongjiang", "city": "Hegang"} "publish_date": "2013-11-11", "read_num": 1999," tag ": [" Classical "," masterpiece "]} POST lqz2/_doc/2 {" title ":" Journey to the West "," price ": 22," publish_addr ": {" province ":" Shanghai "," city ":" Shanghai "}," publish_date ":" 2013-11-11 "," read_num ": 66 "tag": ["Classical", "novel"]} # 2 query documentation (more detailed search Later on) GET lqz2/_doc/2# 3 modified document-overlay (the original field is gone) PUT lqz/_doc/1 {"title": "xxxx", "price": 333," publish_addr ": {" province ":" Heilongjiang " "city": "Fuzhou"}}-incremental (only modify a field) be sure to pay attention to the package POST lqz2/_doc/1/_update {"doc": {"title": "xx"}} # 4 delete the document DELETE lqz/_doc/1# 5 get GET _ mget {"docs": [{"_ index": "lqz2", "_ type": "_ doc" in batch "_ id": 2}, {"_ index": "lqz2", "_ type": "_ doc", "_ id": 1}]} # 6 bulk insert PUT test/_doc/2/_create {"field1": "value22"} POST _ bulk {"index": {"_ index": "test" "_ id": "1"} {"field1": "value1"} {"delete": {"_ index": "test", "_ id": "2"}} {"create": {"_ index": "test" "_ id": "3"} {"field1": "value3"} {"update": {"_ id": "1", "_ index": "test"} {"doc": {"field2": "value2"} 5 document query # Test data PUT lqz/doc/1 {"name": "Gu Laoer", "age": 30, "from": "gu" "desc": "dark skin, long arms, straight character", "tags": ["black", "long", "straight"]} PUT lqz/doc/2 {"name": "Lady", "age": 18, "from": "sheng", "desc": "fair skin and beautiful face" Jiao Han cute "," tags ": [" white "," rich "," beautiful "]} PUT lqz/doc/3 {" name ":" dragon set partial room "," age ": 22," from ":" gu "," desc ":" mmp, not much. I don't know how to describe it, "tags": ["create data", "true" Difficult]} # two ways-the first (string query) GET lqz/doc/_search?q=from:gu GET lqz/doc/_search?q=age:22-the second (structured) query GET lqz/doc/_search {"query": {"match": {"from": "gu"} } GET lqz/doc/_search {"query": {"match": {"age": 22}} GET lqz/doc/_search {"query": {"match": {"desc": "describe"}} GET lqz/doc/_search {"query": {"match": {"tags": "creating data"} this is the end of the introduction of "methods for adding, deleting, modifying and querying Elasticsearch document Index". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report