分词查询
GET car/_analyze
{
"text":"内容"
}
增加数据
POST news/_doc
{
"name":"你好"
}
查询
GET news/_search
{
"track_total_hits": true,
"size":300,
"from" : 0,
"query" : {
"bool" : {
"must" : [
{"match_phrase" :
{
"id" :1308044628750348294
}
}
]
}
}
}
删除
POST news/_delete_by_query
{
"query" : {
"bool" : {
"must" : [
{"match_phrase" :
{
"id" :1310464974484774913/1308044628750348294
}
}
]
}
}
}
更新
POST news/_update_by_query
{
"script": {
"source": "ctx._source['created_at']=1600697116"
},
"query" : {
"bool" : {
"must" : [
{"match_phrase" :
{
"id" :1308044628750348294
}
}
]
}
}
}
#更新多个字段
POST suoyin/_update_by_query
{
"script": {"source": "ctx._source.字段1 = params.字段1_s;ctx._source.字段2 = params.字段2_s",
"lang": "painless",
"params" : {
"字段1_s" : 100,
"字段2_s": 100
}
},
"query" : {
"bool" : {
"must" : [
{"match_phrase" :
{
"id" :1
}
}
]
}
}
}
创建索引
POST hwyy_live_person_case/_doc
{
}
索引添加字段
注:es7.x 以上版本需要在索引上添加&include_type_name=false
POST news/_mapping?pretty
{
"properties": {
"a": {
"type": "long"
},
"b": {
"type": "text"
},
"created_at": {
"type": "long"
},
"id": {
"type": "long"
},
"c": {
"type": "keyword"
},
"updated_at": {
"type": "long"
},
"updated_by": {
"type": "long"
}
}
}
#去重聚合超过限制解决方案
PUT /_cluster/settings
{"persistent": {"search.max_buckets": 999999999}}
#分页过多限制解决方案
PUT 索引名/_settings
{
"index": {
"max_result_window": 999999999
}
}
Elasticsearch中的mapping,就不能再修改。新增字段
/索引/_mapping/类型
{
"customer": { //类型
"properties": {
"submit_channels": { //新增字段
"type": "string",
"index": "not_analyzed"
}
}
}
}
ES关于聚合优化字段报下面错误
Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true
PUT 索引/_mapping
{
"properties": {
"字段": {
"type": "text",
"fielddata": true
}
}
}
fielddata在text字段中默认未启用
因为fielddata会消耗大量的堆内存,特别是当加载大量的text字段时;fielddata一旦加载到堆中,在segment的生命周期之内都将一致保持在堆中,所以谨慎使用
多字段去重
"aggs":{
"uid_aggs":{
"cardinality": {
"script":"doc['feild1'].toString + doc['feild2'].toString" # 任意多个字段
}
}
}