1. ES 增加字段 设置默认值
```
PUT hwyy_qq_friends/_mapping
{
"properties": {
"last_talk_time":{
"type": "long"
}
}
}
POST hwyy_qq_friends/_update_by_query
{
"script": {
"lang": "painless",
"inline": "if (ctx._source.last_talk_time== null) {ctx._source.last_talk_time= '0'}"
}
}
```
2. ES group by count
GET /cars/transactions/_search
{
"size" : 0,
"aggs" : {
"distinct_colors" : {
"cardinality" : {
"field" : "color"
}
}
}
}
2.1. collapse(折叠)介绍
- Field Collapsing(字段折叠)不能与scroll、rescore以及search after 结合使用。
- 使用collapse 的字段如果是 string类型,则es 中对应 keyword。(The field used for collapsing must be a single valued keyword or numeric field with doc_values activated)
- 查看collapse 结果
(1)GET user/_search
{
"query": {
"match": {
"address": "Place"
}
},
"collapse" : {
"field" : "age"
},
"sort": ["age"],
"from": 10
}
(2)Expand collapse results(对于每个折叠的结果,可以通过inner_hits展开结果)
// 单个inner_hits
GET user/_search
{
"query": {
"match": {
"address": "Place"
}
},
"collapse" : {
"field" : "age",
"inner_hits": {
"name": "test",
"size": 5,
"sort": [{ "age": "asc" }]
},
"max_concurrent_group_searches": 4
},
"sort": ["age"]
}
// 多个inner_hits
GET user/_search
{
"query": {
"match": {
"address": "Place"
}
},
"collapse" : {
"field" : "age",
"inner_hits":[ {
"name": "age",
"size": 2,
"sort": [{ "age": "asc" }]
},
{
"name":"account_number",
"size": 2,
"sort": [{ "account_number": "asc" }]
}],
"max_concurrent_group_searches": 4
},
"sort": ["age"]
}
// max_concurrent_group_searches:允许每组检索inner_hits的并发请求数 (默认按照线程池的大小或者数据节点数)
3、查看collapse 结果
3. ES 分页最大页数
PUT /hwyy_wechat_qun_member_list/_settings
{
"index": {
"max_result_window": 999999999
}
}
4. 字段设计
“content” : {
“type” : “text”,
“fields” : {
“keyword” : {
“type” : “keyword”,
“ignore_above” : 256
}
}
}
5. 查询不为空字符串的字段
POST /hwyy_test_archives_list/_search
{
"track_total_hits": true,
"query": {
"bool": {
"must_not": [
{
"match": {
"qq.keyword": ""
}
}
]
}
}
}
6. 复制数据
POST _reindex
{
"source": {
"index": "hwyy_test_fence_site_code"
},
"dest": {
"index": "hwyy_live_fence_site_code",
"op_type": "create"
}
}
7. 指定字段更新
POST hwyy_live_person/_update/k7ksv3QBCeP_Wxhg7HNw
{
"doc" : {
"person_id_no_img" : ""
}
}