Elasticsearch distributed installation steps 1
#Consider the need to install elasticsearch-head for web display, so install nodejs first, mainly using npm wget https://npm.taobao.org/mirrors/node/v11.0.0/node-v11.0.0.tar.gz tar - zxvf node-v11.0.0.tar.gz mv node-v11.0.0 /opt/soft/ cd /opt/soft/node-v11.0.0 yum install gcc gcc-c++ ./configure make make install node -v
Step 2
cd /opt/ tar -zxf elasticsearch-6.7.1.tar.gz mv elasticsearch-6.7.1 /opt/soft/ cd /opt/soft/es671/config/ vim elasticsearch.yml ========= ===== #Modify cluster.name: es-app node.name: es-1 network.host: 192.168.64.128 http.port: 9200 #Insert http.cors.enabled: true http.cors.allow-origin: "*" ============== :wq #Create a user useradd cm passwd cm ok ok su cm su vim /etc/security/limits.conf #Append question 1 to the end of the file System Max The number of files is too low cm soft nofile 65536 cm hard nofile 131072 cm soft nproc 4096 cm hard nproc 4096 vim /etc/sysctl.conf #Append to the end of the file Problem 2 Virtual memory is too low vm.max_map_count=655360 #Activate sysctl -p #Authorize chown cm:cm -R /opt/soft/es671/ su cm cd. . cd /opt/soft/es671/bin/ ls ./elasticsearch #Browser view 192.168.64.128:9200
Step 3(open new window)
cd /opt/ #Install zip yum install -y unzip zip #Unzip elasticsearch-head-master.zip mv elasticsearch-head-master /opt/soft/eshead cd /opt/soft/eshead/ #Tell the system to import the package Finally, there is a file that cannot be found and an error is reported (not important and does not affect development) npm install #Open a new window cd /opt/soft/eshead npm run start #Browser access http://192.168.64.128:9100
ElasticSearch02
rowid
Used to locate a certain piece of data in the data table. It is unique and will not change.
rownum
Indicates querying the position of a certain record in the entire result set. The rownum corresponding to different query conditions for the same record is different, but the rowid will not change.
Start es
Configure environment variables vim /etc/profile =========================== #Elasticsearch export Elasticsearch_Home=/opt/soft/es671 export PATH=$ PATH:$Elasticsearch_Home/bin =========================== source /etc/profile su cm cd /opt/soft/es671/bin . /elasticsearch #Start. /elasticsearch -d #Stop su cd /opt/soft/eshead npm run start 192.168.64.128:9100 #Browser access #If you want to install a cluster, remember vim elasticsearch.yml node.name: es- 1 needs different
es creates index
method 1
put indexTest001 put /my_test_index_004
Method 2
es operation basic data
1Create table
2. Add data
3. Modify data
4. Delete data
5. Add data in batches
6. Query by id
7. Query all
8. Fuzzy query
9. Phrase Match Query
10. Phrase prefix matching
11.Multiple column query
12.in query query-query_string
13.term query query-term
14.Multi-vocabulary query
15. Range query
16. Boolean query
Install
Chinese word segmentation installation
Prerequisite is to drag in the jar package
mkdir ik mv elasticsearch-analysis-ik-6.7.1.zip ik/ ls cd ik/ unzip elasticsearch-analysis-ik-6.7.1.zip cd .. mv ik/ /opt/soft/es671/plugins/ cd /opt/soft/es671/plugins/ ls cd ../.. chown cm:cm -R /opt/soft/es671/ su cm cd es671/bin/ ./elasticssearch -d su cd /opt/soft/eshead npm run start
.ik word segmenter test
.1 Use of tokenizer
springboot integration es
The first step is to import pom
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.0.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <repositories> <repository> <id>spring-snapshots</id> <url>http://repo.spring.io/libs-snapshot</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <url>http://repo.spring.io/libs-snapshot</url> </pluginRepository> </pluginRepositories>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency>
The second step is to configure yml
server: port: 8001 spring: application: name: myelastics elasticsearch: rest: uris: 192.168.64.128:9200
The third step is to configure the entity class
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Document(indexName = "mydemo1",type= "userinfos" )
public class Userinfos {
@Id
private String id;
@Field(type = FieldType.Integer,name = "userid")
private Integer userid;
@Field(type = FieldType.Text,name = "username")
private String username;
@JsonFormat(pattern = "yyyy-MM-dd")
@Field(type = FieldType.Date,name = "birthday",format = DateFormat.date)
private Date birthday;
}
Step 4 Configure the mapper interface
public interface UserinfosMapper extends ElasticsearchRepository<Userinfos,String> { }
Step 5: Configure test query
@SpringBootTest class Es05ApplicationTests { @Resource private UserinfosMapper userinfosMapper; @Test void contextLoads() { //The first query based on id // Optional<Userinfos> op = userinfosMapper.findById("222"); //If it is empty, no error will be reported // op.ifPresent(a-> System.out.println(a)); // System.out.println(op.get()); //The second fuzzy query MatchQueryBuilder qbmq = QueryBuilders.matchQuery("username ", "Zhang Wuji"); Iterable<Userinfos> search = userinfosMapper.search(qbmq); //lamda method refers to the traversal results search.forEach(System.out::println); } }
View Results!