首页 > 数码百科 >

elasticsearch菜鸟教程

数码百科 2024-04-22 03:35:36

Elasticsearch是一个基于Lucene的搜索引擎,提供了全文搜索、结构化搜索、分析等功能,以下是一个简单的Elasticsearch教程:

1、安装Elasticsearch

可以从官方网站下载Elasticsearch并按照说明进行安装。

2、启动Elasticsearch

在命令行中输入以下命令启动Elasticsearch:

```

bin/elasticsearch

```

3、使用Elasticsearch

可以使用curl命令或者Postman等工具向Elasticsearch发送请求,创建一个名为my_index的索引:

```

curl -X PUT "localhost:9200/my_index"

```

4、添加文档

向my_index索引中添加一个文档:

```

curl -X POST "localhost:9200/my_index/_doc" -H 'Content-Type: application/json' -d'

{

"name": "张三",

"age": 30,

"city": "北京"

}'

```

5、查询文档

查询my_index索引中的所有文档:

```

curl -X GET "localhost:9200/my_index/_search"

```

查询name为张三的文档:

```

curl -X GET "localhost:9200/my_index/_search" -H 'Content-Type: application/json' -d'

{

"query": {

"match": {

"name": "张三"

}

}

}'

```

6、更新文档

更新my_index索引中的某个文档:

```

curl -X POST "localhost:9200/my_index/_update/1" -H 'Content-Type: application/json' -d'

{

"doc": {

"age": 31

}

}'

```

7、删除文档

删除my_index索引中的某个文档:

```

curl -X DELETE "localhost:9200/my_index/_doc/1"

```

8、删除索引

删除my_index索引:

```

curl -X DELETE "localhost:9200/my_index"

```

以上就是一个简单的Elasticsearch教程,希望对你有所帮助。


标签:

杰艾尔技巧网 Copyright©2023www.jieapp.com 鄂ICP备2021007786号-18