找的解决方案,因为索引字段已经有数据
1. 新建索引,将mappings的show_num字段,index设置为true
2. 将旧索引的数据,复制到新索引
3. 删除旧索引
没采用新建索引,使用新增字段解决
1. 查询mapping,检测里边是否有需要新增的字段,没有再去新增
URL:http://IP/test_log_20240710-0/_mapping
请求方式:GET
2. 新建字段,index设置为true
新建/更新mapping字段
URL:http://IP/test_log_20240710-0/_mapping
请求方式:PUT
参数:
{
"properties": {
"show_num_indexed": {
"type": "long",
"index": true,
"doc_values": false
}
}
}
3. 将不能做查询的旧字段数据,赋值给新字段
将某个字段的值,赋值给新字段
URL:http://IP/test_log_20240710-0/_update_by_query
请求方式:POST
参数:
{
"script": {
"source": "ctx._source.show_num_indexed = ctx._source.show_num"
}
}
4. 使用新字段做查询即可
{
"size": 10,
"query": {
"bool": {
"must": [
{
"term": {
"status": 200
}
},
{
"term": {
"show_num_indexed": 12345
}
}
]
}
}
}