PUT /index_script_fields
{"mappings":{"runtime":{"aggLineName":{"type":"keyword","script":{"source":"emit(doc['lineName'].value)"}}},"properties":{"lineId":{"type":"keyword"},"lineName":{"type":"text"}}}}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
3.1.2、更新 runtime field
POST /index_script_fields/_mapping
{"runtime":{"aggLineName":{"type":"keyword","script":{"source":"emit(doc['lineName'].value)"}}}}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
3.1.3、删除runtime field
POST /index_script_fields/_mapping
{"runtime":{"aggLineName":null}}
1.
2.
3.
4.
5.
6.
3.2 通过search request定义runtime field
GET /index_script_fields/_search
{"runtime_mappings":{"lineName":{"type":"keyword","script":"emit(params['_source']['lineName']+'new')"}},"query":{"match_all":{}},"fields":["lineName"]}
PUT /index_script_fields
{"mappings":{"properties":{"lineId":{"type":"keyword"},"lineName":{"type":"text"}}}}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
注意此时的lineName的类型是text
5.2 插入数据
PUT /index_script_fields/_bulk
{"index":{"_id":1}}{"lineId":"line-01","lineName":"线路A"}{"index":{"_id":2}}{"lineId":"line-01","lineName":"线路A"}{"index":{"_id":3}}{"lineId":"line-02","lineName":"线路C"}
GET /index_script_fields/_search
{"runtime_mappings":{"aggLineName":{"type":"keyword","script":"emit(params['_source']['lineName']+'new')"}},"query":{"match_all":{}},"fields":["lineName"],"aggs":{"agg_line_name":{"terms":{"field":"aggLineName","size":10}}}}