bboss oreach循环嵌套遍历map
Posted -flq
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bboss oreach循环嵌套遍历map相关的知识,希望对你有一定的参考价值。
foreach循环嵌套遍历map
foreach嵌套dsl脚本定义
<property name="dynamicInnerDsl">
<![CDATA[{ ## 最多返回1000条记录
size: #[size],
"query": {
"bool": {
"must": [
#set($needComma = false)
#foreach($condition in $conditions.entrySet())
#foreach($item in $condition.value.entrySet())
#if($needComma), #else #set($needComma = true) #end
{
"$condition.key": {
"$item.key": #[conditions[$condition.key][$item.key],serialJson=true]
}
}
#end
#end
]
}
}
}]]>
</property>
传递参数和解析上述dsl的java方法代码
@Test
public void dynamicInnerDsl(){
Map conditions = new HashMap<String,Map<String,Object>>();
Map<String,Object> term = new HashMap<String, Object>();
term.put("terma","tavalue");
term.put("termb","tbvalue");
term.put("termc","tcvalue");
conditions.put("term",term);
Map params = new HashMap();
params.put("conditions",conditions);
params.put("size",1000);
//加载配置文件中的dsl信息,解析dsl语句dynamicInnerDsl
ESUtil esUtil = ESUtil.getInstance("esmapper/dsl.xml");
String parseResult = ESTemplateHelper.evalTemplate(esUtil,"dynamicInnerDsl",params);
//打印解析结果
System.out.println(parseResult);
}
运行上述代码打印出来的实际dsl
{
"size": 1000,
"query": {
"bool": {
"must": [
{
"term": {
"termb": "tbvalue"
}
},
{
"term": {
"termc": "tcvalue"
}
},
{
"term": {
"terma": "tavalue"
}
}
]
}
}
}
以上是关于bboss oreach循环嵌套遍历map的主要内容,如果未能解决你的问题,请参考以下文章