Descargue los paquetes de instalación de elasticsearch y kibana
Enlace original: https://juejin.cn/post/7261262567304298554
elasticsearch
La descarga desde el sitio web oficial es relativamente lenta y, a veces, no se puede abrir. Puede descargarla a través de https://elasticsearch.cn/download/ , busque primero la versión correspondiente y es mejor usar Thunder para descargar. segundos, mi velocidad de descarga puede llegar a 40M/S
Descomprimir e instalar
instalar elasticsearch
Después de la descompresión, haga clic para elasticsearch-7.10.0\bin\elasticsearch.bat
ejecutar correctamente, ingrese http://120.0.0.1:9200 , puede acceder a él, lo que indica que el inicio de ES es exitoso
instalar kibana
Después de hacer clic kibana-7.10.0-windows-x86_64\bin\kibana.bat
para iniciar con éxito, ingrese http://localhost:5601/ para ingresarkibana
Configurar la contraseña de la cuenta de inicio de sesión
ealsticsearch establece la contraseña de la cuenta
Abra config/ealsticsearch.yml
Agregar para habilitar la configuración de contraseña y luego reinicieealsticsearch
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
Ingrese .\bin\elasticsearch-setup-passwords.bat interactive
la contraseña de configuración. Aquí hay algunas contraseñas de cuentas integradas de ES. Por ejemplo, kibana_system
esta contraseña de cuenta debe configurarse en el kibana.yml
medio. Tengo que recordarla aquí. Lo configuré para pruebas locales 123456
. La seguridad de la contraseña del El entorno de producción debe configurarse más alto y no se pueden usar contraseñas simples .
PS D:\service\ES\elasticsearch-7.10.0> .\bin\elasticsearch-setup-passwords.bat interactive
future versions of Elasticsearch will require Java 11; your Java version from [C:\Program Files\Java\jdk1.8.0_191\jre] does not meet this requirement
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Passwords do not match.
Try again.
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
Abra http://localhost:9200 nuevamente , ingrese el elastic
número de cuenta y la contraseña 123456
, y si el inicio de sesión es exitoso, la configuración de la contraseña es exitosa;
Establecer contraseña de cuenta es en kibana
Después de abrir kibana-7.10.0-windows-x86_64\config\kiban.yml
y configurar la contraseña de la cuenta, reinicie kibana
e ingrese localhost:5601 nuevamente para iniciar sesión con la contraseña de la cuenta
elasticsearch.hosts: ["http://localhost:9200"]
elasticsearch.username: "kibana_system"
elasticsearch.password: "123456"
guía de datos de prueba
Use Kiban
crear índice e importar datos de prueba, haga clic kiban
para dev Tools
ejecutar crear índice e insertar datos
PUT /news
{
"mappings": {
"properties": {
"id": {
"type": "long"
},
"title": {
"type": "text",
"analyzer": "standard"
},
"tags": {
"type": "keyword"
},
"read_count": {
"type": "long"
},
"like_count": {
"type": "long"
},
"comment_count": {
"type": "long"
},
"rank": {
"type": "double"
},
"location": {
"type": "geo_point"
},
"pub_time": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd HH:mm||yyyy-MM-dd||epoch_millis"
}
}
}
}
POST _bulk
{
"create": {
"_index": "news", "_id": 1}}
{
"comment_count":600,"id":1,"like_count":2000,"location":[118.55199,24.78144],"pub_time":"2023-07-29 09:47","rank":0.0,"read_count":10000,"tags":["台风","杜苏芮","福建"],"title":"台风“杜苏芮”登陆福建晋江 多部门多地全力应对"}
{
"create": {
"_index": "news", "_id": 2}}
{
"comment_count":60,"id":2,"like_count":200,"location":[116.23128,40.22077],"pub_time":"2023-06-29 14:49:38","rank":0.0,"read_count":1000,"tags":["台风","杜苏芮","北京"],"title":"受台风“杜苏芮”影响 北京7月29日至8月1日将有强降雨"}
{
"create": {
"_index": "news", "_id": 3}}
{
"comment_count":6,"id":3,"like_count":20,"location":[120.21201,30.208],"pub_time":"2020-07-29 14:49:38","rank":0.99,"read_count":100,"tags":["台风","杭州"],"title":"杭州解除台风蓝色预警信号"}
Conexión de cliente JAVA
pom
introducirelasticsearch-rest-high-level-client
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.10.0</version>
</dependency>
Crear RestHighLevelClient
y completar la consulta
public static RestHighLevelClient esClient;
static {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "123456"));
RestClientBuilder builder = RestClient.builder(new HttpHost("127.0.0.1", 9200))
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
esClient = new RestHighLevelClient(builder);
}
public static Map<String, Object> getById(String index, String id) throws IOException {
GetRequest request = new GetRequest(index, id);
GetResponse getResponse = esClient.get(request, RequestOptions.DEFAULT);
return getResponse.getSourceAsMap();
}
public static void main(String[] args) throws IOException {
var doc=getById("news","1");
doc.forEach((k,v)-> System.out.println(k+":"+v));
}
prueba de funcionamiento
La prueba ha pasado y la consulta se puede completar