弹性搜索基于日期时间字段的评分

时间:2017-02-27 11:55:32

标签: elasticsearch aggregate scoring

如何根据日期字段在Elasticsearch中编写自定义评分功能

任何人都可以帮我根据日期字段在Elasticsearch中编写自定义Scoreing功能吗?

如果我将日期字段设为asc,它将使用其他评分函数来计算得分,最后如果使用asc我需要将得分添加到最近几天的文档中,如果desc得分应基于最近几天

1 个答案:

答案 0 :(得分:0)

我打赌你所寻找的是所谓的Function Queries。 如果是日期,您可以使用field_value_factor。它将获取您的日期值并将其转换为毫秒(Unix时间戳)。所以你应该提供如下的smth:

/**
   * Checks if the device is rooted.
   *
   * @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
   */
  public static boolean isRooted() {

    // get from build info
    String buildTags = android.os.Build.TAGS;
    if (buildTags != null && buildTags.contains("test-keys")) {
      return true;
    }

    // check if /system/app/Superuser.apk is present
    try {
      File file = new File("/system/app/Superuser.apk");
      if (file.exists()) {
        return true;
      }
    } catch (Exception e1) {
      // ignore
    }

    // try executing commands
    return canExecuteCommand("/system/xbin/which su")
        || canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
  }

  // executes a command on the system
  private static boolean canExecuteCommand(String command) {
    boolean executedSuccesfully;
    try {
      Runtime.getRuntime().exec(command);
      executedSuccesfully = true;
    } catch (Exception e) {
      executedSuccesfully = false;
    }

    return executedSuccesfully;
  }
相关问题