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

Analysis of the use example of elasticsearch

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

The use of elasticsearch example analysis, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Elasticsearch is a Lucene-based search server. It provides a full-text search engine with distributed multi-user capability, based on RESTful web interface.

1. Basic concepts:

1. Index (index)

Is Elasticsearch's logical storage of logical data, so it can be divided into smaller parts. An index can be thought of as a table in a relational database, and the structure of the index is prepared for a fast and efficient full-text index, especially when it does not store the original values. Elasticsearch can store indexes on one machine or on multiple servers, each index has one or more shard, and each shard can have multiple copies (replica).

two。 Document (document)

The main entity stored in the Elasticsearch is called a document. Using a relational database analogy, a document is equivalent to a row of records in a database table.

3.Mapping

Mapping is to pre-define the data type of each field in the document, such as defining a certain field in the document for shaping, what parser to use, whether it is searchable, etc., an index can define multiple mapping.

Second, basic operations:

1. Add new index and set mapping

The http://ip:9200/ index name / body of the PUT request is as follows {"settings": {"number_of_shards": 3, "number_of_replicas": 1}, "mappings": {"properties": {"video_like": {"type": "long"}, "video_date": {"type": "date" "format": "yyyy-MM-dd HH:mm:ss | | yyyy-MM-dd | | epoch_millis"}, video_title: {"analyzer": "ik_smart", "type": "text"}, "video_comment": {"type": "long"}, "share_conut": {"type": "long"} "video_img_url": {"type": "text"}, "video_url": {"type": "text"}, "type_id": {"type": "long"}, "updata_time": {"type": "date", "format": "yyyy-MM-dd HH:mm:ss | | yyyy-MM-dd | | epoch_millis"} User_id: {"type": "long"}

Number_of_replicas is the number of data backups, if there is only one machine, set to 0 # numbered of data shards is the number of data shards, default to 5, sometimes set to 3.

two。 Add mapping fields to existing indexes

PUT request http://ip:9200/index/_mapping

{"properties": {"name": {"type": "text"}

Index is the name of your index library. What is written in body is the field name and field type to be added. The above example is the new name field with the type text.

3. Determine whether a field is empty or not

Http://ip:9200/index/_search

{"query": {"bool": {"must_not": {"exists": {"field": "label"}

When inserting data into es, if a field is empty, I do not write a value to that field, so I can determine whether a field is null or not and directly determine whether the field exists. Use exists to determine whether a field exists. This example is to determine whether the value of label is empty.

4.must multiple conditions

Http://ip:9200/index/_search

{"query": {"bool": {"must": [{"range": {"video_date": {"gte": "now-24h+8h" "lte": "now+8h"} {"exists": {"field": "label"}

When there are multiple conditions in must, the corresponding parameter type is a list. The above example: the search must be the result of a video_date in a certain time range and the label field exists.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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

Internet Technology

Wechat

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

12
Report