Elasticsearch profile

Elasticsearch is a highly extensible open source full-text search and analysis engine based on Lucene. The website describes a programmer who wanted to build a recipe search engine for his wife, a chef. Developed using Lucene and later developed into elasticSearch. The first version was released in 2010, and github is now particularly active. Today, there are 1100 Github contributors and 223 releases.

Elasticsearch is an example of how powerful elasticSearch is, as it allows users to store and analyze large amounts of data quickly and in near real time (insert to searchable usually in 1 second).

Elasticsearch features

1. Fast speed. Elasticsearch indexes all the content. 2, scalability, you can run ElasticSearch on a single node, production environment can be in a 300 node cluster. So you can increase the capacity of nodes horizontally to handle requests. 3. High availability. Provided with a copy, the master node is down, you can detect the fault and re-select a new node. 4. Flexibility. Numbers, text, geography, structured, unstructured. There are many data types supported. Application search, security analysis, and logging all rely on Elasticsearch to solve various challenges.

Some concepts for ElasticSearch.

header header
Cluster cluster A cluster consists of one or more nodes with the same name.
Node node A node node is an instance of ElasticSearch. You can set whether you can be a master node, a data node, or a coordination node. Users can communicate with any node in the cluster, including the primary node. Each node knows which node the document resides on and can forward requests to the appropriate node.
Shard shard A shard is the smallest unit of work, holding only a fraction of all the data in the index. The default is 5 shards and 1 copy.
The primary shard Each document in the index belongs to a separate master shard, so the number of master shards determines how much data the index can store. When the index is created, the number of primary shards is fixed, but the number of replication shards can be adjusted at any time.
Copy the shard Is a copy of the master shard, which protects against data loss due to hardware failures and provides read requests, such as searching or retrieving documents from other shards
The index index An index is a collection of documents with similar characteristics, and it is not quite the same concept as an index in a database. We can think of an index as a database in a database document. In fact, our data is stored and indexed in shards, an index is just a logical space that groups one or more shards together. However, these are just internal details — our program doesn’t care about sharding at all
Type type In the index, we can define one or more types. A type is a logical category/partition of an index whose semantics are entirely up to the developer. Typically, you define a type for a document that has a common set of fields. For example, suppose a developer runs a blogging platform and stores all data in an index. In this index, we can define a type for user data, another type for blog data, and another type for annotation data. We can think of an index as a table in a database document.
The document A record

The following simple analogy is es and Relational database Relational DB – > Databases – > Tables – > Rows – > Columns Elasticsearch – > Indices (index cluster) – > Types – > Documents -> Fields

Cluster Environment Construction

The ElasticSearch cluster is created

As a demonstration, I set up a three-node cluster using a single server. Since the default JVM memory size for a node is 2 gb, I only had 2 GB on a server, and in the config directory I changed the Jvm.oprion configuration to -xms and -xmx to 512 MB

The number of nodes is officially n/2+1 nodes in order to prevent brain splitting. Split brain refers to the primary node of the three nodes has problems and cannot be connected, so a primary node will be elected from the remaining two nodes. However, the former primary node recovers, and the newly elected primary node can be demoted to the secondary node according to the third node. But with two nodes, it is not clear who will be demoted.

Now the latest version is 6.4.2 download down. The official website can be downloaded directly. Then unzip and make three copies. The configuration file is as follows:








Elasticsearch Head visualization tool

Node.js is a node.js development tool, so you need to install node.js. Download address: github.com/mobz/elasti… Or Download button, click Download Zip to download. After downloading the elasticSearch file, decompress it to any directory, not the installation directory of ElasticSearch.

Allow origin to modify elasticSearch configuration files across domains.
http.cors.enabled: true
http.cors.allow-origin: "*"
Copy the code

Start using Grunt Server & background

Use of plug-ins (IK, Pinyin, SQL)

You can download the plugin directly from Github. Note: The plugin version must be the same as elasticSearch.

Install the Chorme Sense tool and you can search for it yourself. You can perform the curl operation

Elasticsearch javaApi operation

Add, delete and change their own demo. Git address.

[email protected]:wanjiongheng/mysql-to-elasticsearch.git

This is the configuration when creating the index: {"state": "open"."settings": {
        "index": {
            "number_of_shards": "3"."number_of_replicas": "0"."analysis": {
                "filter": {
                    "my_pinyin": {
                        "keep_joined_full_pinyin": "true"."none_chinese_pinyin_tokenize": "false"."keep_none_chinese_in_joined_full_pinyin": "true"."keep_original": "true"."keep_first_letter": "false"."keep_separate_first_letter": "false"."type": "pinyin"."keep_full_pinyin": "false"}},"analyzer": {
                    "ik_pinyin_analyzer": {
                        "filter": [
                            "my_pinyin"."word_delimiter"]."type": "custom"."tokenizer": "ik_smart"}}}}},"mappings": {
        "goods": {
            "properties": {
                "name_pinyin": {
                    "type": "keyword"
                },
                "note": {
                    "type": "keyword"
                },
                "flag": {
                    "type": "integer"
                },
                "modifyTime": {
                    "type": "long"
                },
                "brand_pinyin": {
                    "type": "keyword"
                },
                "createTime": {
                    "type": "long"
                },
                "price": {
                    "type": "keyword"
                },
                "name": {
                    "type": "keyword"."fields": {
                        "ik_smart_pinyin_analyzer": {
                            "analyzer": "ik_pinyin_analyzer"."term_vector": "with_positions_offsets"."type": "text"}}},"id": {
                    "type": "long"
                },
                "brand": {
                    "type": "keyword"."fields": {
                        "ik_smart_pinyin_analyzer": {
                            "analyzer": "ik_pinyin_analyzer"."term_vector": "with_positions_offsets"."type": "text"}}},"useState": {
                    "type": "integer"}}}},"aliases": [
        "goods_alias"],}Copy the code

Finally, the ElasticSearch API is extensive. You can learn by yourself.