赞
踩
Elasticsearch source filter检索案例分享
1.准备工作
先理解一下es source filter作用:通过在_source中指定includes和excludes,控制查询结果中哪些source字段要返回、哪些source字段不需要返回,source filter的dsl定义语法如下:
{
"_source": {
"includes": [ "obj1.*", "obj2.*" ],
"excludes": [ "*.description" ]
},
"query" : {
"term" : { "user" : "kimchy" }
}
}
本文演示动态从外部传入includes和excludes实现source filter功能,适用于includes和excludes动态变化的source filter场景。
2.定义source filter dsl语句
首先,在DocumentCRUD案例对应的dsl配置文件esmapper/demo.xml中添加searchSourceFilter:
#if($includes || $excludes) ## 只有指定了includes或者excludes才需要添加source filter
"_source": {
#if($includes ) ##设置includes filter
"includes": [
#foreach($
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。