当前位置:   article > 正文

es查询语句java使用_source_Elasticsearch source filter检索案例分享

es “-source” 在java

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($

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/68220?site
推荐阅读
相关标签
  

闽ICP备14008679号