美文网首页
ElasticSeach进阶

ElasticSeach进阶

作者: 蓝色Hippie | 来源:发表于2020-09-07 06:48 被阅读0次

可用poatman测试

一、索引

1.查看集群健康:GET  http://192.168.31.221:9200/_cluster/health

2.创建索引(名为index_test): PUT  

http://192.168.31.221:9200/index_test  

body:(number_of_shards:分片数;number_of_replicas:副本数)

{

 "settings": {

        "index": {

            "number_of_shards": "2",

            "number_of_replicas": "0"

        }

    }

}

3.查看所有索引信息: GET  http://192.168.31.221:9200/_cat/indices?v

4.删除索引(名为index_test):DELETE   http://192.168.31.221:9200/index_test 

二、映射(数据类型/数据结构的设置)

1.创建索引的同时创建mappings(索引名为index_str): PUT   http://192.168.31.221:9200/index_str

body:

{

    "mappings": {

        "properties": {

            "realname": {

            "type": "text",

            "index": true

            },

            "username": {

            "type": "keyword",

            "index": false

            }

        }

    }

}

2.查看分词效果 (索引名为index_str) GET  http://192.168.31.221:9200/index_str/_analyze

body:

{

"field": "realname",

"text": "imooc is good"

}

3.为已存在的索引index_str创建或增加映射:  POST   http://192.168.31.221:9200/index_str/_mapping

body:

一旦某个属性被建立,就不能修改了,但是可以新增额外属性

3.主要数据类型

text、keyword、string(已启用)

long、integer、short、byte

double、float

boolean、date、object

数组不能混,类型保持一致

三、文档

1.添加文档数据:{索引名}/_doc/{索引ID}(索引id是指数据在es中的id,而不是这条记录的id) 

POST   http://192.168.31.221:9200/my_cod/_doc/1

body:

{

    "id": 1001,

    "name": "imooc-1",

    "desc": "imooc is very good, 慕课网非常牛!",

    "create_date": "2019-12-24"

}

注:

如果索引没有手动建立mappings,那么当插入文档数据的时候,会根据文档类型设置属性类型。这个就是es的动态映射,帮助我们在index索引库去建立数据结构的相关配置

"fileld":{"type":"password"}对一个字段设置多种索引模式,使用text类型做全文检索,也可以使用keyword类型做聚合和排序

“ignore_above”:256 设置的索引和存储的最大值,超过则被忽略

2.删除文档

根据索引id删除:

DELETE    http://192.168.31.221:9200/my_cod/_doc/1

3.修改文档

局部(更新索引id为1的name): POST    http://192.168.31.221:9200/my_cod/_doc/1/_u[date

body:

{

    "doc": {

        "name": "慕课"

    }

}

全量替换:PUT   http://192.168.31.221:9200/my_cod/_doc/1

body:

{

    "id": 1001,

    "name": "imooc-1",

    "desc": "imooc is very good, 慕课网非常牛!",

    "create_date": "2019-12-24"

}

4.常用查询(索引名为index_cod)

根据索引id查询:  GET   url/index_cod/_doc/1

全量查询:GET  url/index_cod/_doc/_search

定制结果集查询(只查询需要的字段):

GET    url/index_cod/_doc/1?_source=id,name

GET    url/index_cod/_doc/_search?_source=id,name

5.更新时文档乐观锁控制

POST    url/my_cod/_doc/{_id}/_update?if_seq_no={数值}&if_primary_term={数值}

{

    "doc": {

        "name": "慕课1"

    }

}

相关文章

  • ElasticSeach进阶

    可用poatman测试 一、索引 1.查看集群健康:GET http://192.168.31.221:9200/...

  • elasticseach

    安装 Elasticsearch 之前,你需要先安装一个较新的版本的 Java,最好的选择是,你可以从www.ja...

  • ElasticSeach

    ES基本概念(ES是非关系型数据库) Index(索引-数据库): ES 数据管理的顶层单位就叫做 Index(索...

  • elasticsearch备份与恢复

    一、参考文档 elasticseach权威指南: https://www.elastic.co/guide/cn/...

  • ElasticSeach相关

    adjust_pure_negative : 默认配置,为了让Lucene能够正确的工作。如果不设置为true,如...

  • ElasticSeach操作

    1.概述 介绍EalsticSearch(基于版本7操作)基本的概念,在kibana的dev tool下进行操作。...

  • Elasticseach初步使用

    最近公司项目需要使用Elasticsearch,所以我去阅读文档初步了解下。Elasticsearch下载后基本...

  • SpringBoot集成ElasticSeach

    1.应入相关依赖 2.创建文档实体 3.编写Repository资源接口,继承于ElasticsearchRepo...

  • 记一次ElasticSearch(ES)的复杂搜索。

    记一次ElasticSearch(ES)的复杂搜索。 ElasticSeach 多条件查询 因为业务需求,需要对同...

  • ElasticSearch(over) - Spring Dat

    1.Spring Data ElasticSeach 1.1 前言 es本身提供java客户端去操作es,但是有一...

网友评论

      本文标题:ElasticSeach进阶

      本文链接:https://www.haomeiwen.com/subject/zdoxektx.html