尝试在OpenSearch中使用日、月、年过滤日期(希望转换Java中的无痛脚本)

f0ofjuux  于 2022-10-01  发布在  Java
关注(0)|答案(1)|浏览(158)
"filter" : [
                {
          "bool" : {
            "must" : [
              {
              "script": {
      "script": """
         int day ;
         int month ;
         int year;

      if ( (int) doc['decisionDate.decisionDay'].size() > 0 && (int) doc['decisionDate.decisionMonth'].size() > 0  && (int) doc['decisionDate.decisionYear'].size() > 0) {

      day = (int) doc['decisionDate.decisionDay'].value;
      month = (int) doc['decisionDate.decisionMonth'].value;
      year = (int) doc['decisionDate.decisionYear'].value;

    return
      ChronoUnit.DAYS.between(ZonedDateTime.of(year, month, day, 0, 0, 0, 0, ZoneId.of('Z')), 
      ZonedDateTime.of(2022, 12, 13, 0, 0, 0, 0, ZoneId.of('Z'))) > 0 && 
      ChronoUnit.DAYS.between(ZonedDateTime.of(2011, 03, 30, 0, 0, 0, 0, ZoneId.of('Z')), 
      ZonedDateTime.of( year,  month, day, 0, 0, 0, 0, ZoneId.of('Z'))) > 0 ; } """

    }
            }
            ]
          }
                }
              ]

上面的代码是OpenSearch中的日期过滤器,带有日、月、年,我正在尝试将其转换为Java脚本。我不知道它是如何转换成Java的

尝试使用插件org.codelibs.fess:fess:14.4.0‘

final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final LabelTypeHelper labelTypeHelper = ComponentUtil.getLabelTypeHelper();
    final LanguageHelper languageHelper = ComponentUtil.getLanguageHelper();

    Script script = ComponentUtil.getLanguageHelper().createScript("here i need add the above (painless script), st);
gijlo24d

gijlo24d1#

这是在OpenSearch中存储的脚本

POST/_脚本/日期过滤器脚本{

"script": {    
                "lang" : "painless",
      "source": """
         int day ;
         int month ;
         int year;

      if ( (int) doc['decisionDate.decisionDay'].size() != 0 ) {
      day = (int) doc['decisionDate.decisionDay'].value;
      }

      if ( (int) doc['decisionDate.decisionMonth'].size() != 0 ) {
      month = (int) doc['decisionDate.decisionMonth'].value;
      }

         if ( (int) doc['decisionDate.decisionYear'].size() != 0 ) {
      year = (int) doc['decisionDate.decisionYear'].value;
      }

      if (day >= 1 && month >= 1 && year >= 1) {
        return
      ChronoUnit.DAYS.between(ZonedDateTime.of(year, month, day, 0, 0, 0, 0, ZoneId.of('Z')), ZonedDateTime.of(params.year_end, params.month_end, params.day_end, 0, 0, 0, 0, ZoneId.of('Z'))) > 0 && ChronoUnit.DAYS.between(ZonedDateTime.of(params.year_start, params.month_start, params.day_start, 0, 0, 0, 0, ZoneId.of('Z')), ZonedDateTime.of( year,  month, day, 0, 0, 0, 0, ZoneId.of('Z'))) > 0 ; } """

    }

}

相关问题