目录
1、在java中创建ES表的字段,在项目中启动同时,如果ES中不存在这个ES表,就会在ES库中自动创建这个表
4、#设置ES最大返回结果(最大返回:10,000,000条数据)
5、为指定字段(introduction等字段)添加使用分词器(ik_smart)
1、在java中创建ES表的字段,在项目中启动同时,如果ES中不存在这个ES表,就会在ES库中自动创建这个表
- 注意:@Document(indexName = "sts_transformproject"),indexName后面的值中不能有大写字母,否则创建表失败
-
@Data @Document(indexName = "sts_transformproject", type = "transformproject") public class TransformProject { @Id private String id; /**项目名称*/ private String name; }
-
2、通过EShead删除数据
- 删除ES中index=data的索引中,code字段值为131的数据(ES版本5.6.3)
-
//删除ES中index=data的索引中,code字段值为131的数据(ES版本5.6.3) Post data/_delete_by_query { "query": { "bool": { "filter": { "term": { "code.keyword": "131" } } } } }
-
3、分词测试
-
#ik_max_word分词 POST _analyze { "tokenizer": "ik_max_word", "text": ["青海湖流域遥感影像on的数据集"] } #ik_smart分词 POST _analyze { "tokenizer": "ik_smart", "text": ["青海湖流域遥感影像on的数据集"] } #standard分词 POST _analyze { "tokenizer": "standard", "text": ["青海湖流域遥感影像on的数据集"] }
4、#设置ES最大返回结果(最大返回:10,000,000条数据)
PUT index/_settings
{
"index":{
"max_result_window":10000000
}
}
5、为指定字段(introduction等字段)添加使用分词器(ik_smart)
PUT indexName
{
"mappings": {
"dataset":{
"properties": {
"introduction":{
"type": "text",
"analyzer": "ik_smart",
"fields": {
"ik": {
"type": "text"
},
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"title":{
"type": "text",
"analyzer": "ik_smart",
"fields": {
"ik": {
"type": "text"
},
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"keyword":{
"type": "text",
"analyzer": "ik_smart",
"fields": {
"ik": {
"type": "text"
},
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"author":{
"type": "text",
"analyzer": "ik_smart",
"fields": {
"ik": {
"type": "text"
},
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
6、删除ES索引中某个字段(参考)
#删除索引中的scoreDiy字段
POST {index}/{type}/_update_by_query
{
"script": {
"lang": "painless",
"inline": "ctx._source.remove(\"scoreDiy\")"
},
"query": {
"match_all": {}
}
}
7、复制索引Ia中的数据到Ib中
#复制索引数据到新的索引中(并且指定将“scoreDiy”的类型由long转换为"string/text",但是不能从“string/text”转为long类型)
POST /_reindex
{
"source": {
"index": "Ia"
},
"dest": {
"index": "Ib"
},
"script": {
"source": "ctx._source.scoreDiy = String.valueOf(ctx._source.scoreDiy)"
}
}
#复制索引data_v2中type=data的数据到索引data_v2_test中
POST /_reindex
{
"source": {
"index": "data_v2",
"type": "data"
},
"dest": {
"index": "data_v2_test"
}
}
8、为索引新增字段
#为索引新增字段:long类型的scoreDiy字段
PUT {indexName}/_mapping/{doc/type}
{
"properties": {
"scoreDiy": {
"type": "long"
}
}
}
9、为索引中的某个字段添加值
#为索引中某个字段(scoreDiy)添加指定值:数字5
POST {indexName}/{type}/_update_by_query
{
"script":{
"source": "ctx._source['scoreDiy']=5;"
}
}
10、修改某个字段的值(根据检索结果)
#修改某个字段的值(根据检索结果) 修改code=Cors中hasMetadata=0
POST {indexName}/{type}/_update_by_query
{
"query": {
"match": {
"code": "Cors"
}
},
"script": {
"source": "ctx._source['hasMetadata'] = 0"
}
}
11、通过shell操作ES
#通过账号+查看,查看索引data_v4的设置
curl -u elastic:密码 -XGET 'http://27.0.0.1:9200/data_v4/_settings'
12、ES查询返回指定字段的值
ES 返回指定字段(name)的值(条件:查询sex=1)
GET {index}/{doc}/_search
{
"_source": "name",
"query": {
"term": {
"sex": {
"value": "1"
}
}
}
}