ES中BKD VS doc value

基于bkd的数字范围查询性能很好,但是由于BKD-Tree内的docId非有序,不能采用类似skipList的向后跳的方式,如果跟其他查询做交集,必须先构造FixedBitSet,这一步可能非常耗时。Lucene中通过IndexOrDocValuesQuery对一些场景做了优化。

在org.apache.lucene.search.join.PointInSetIncludingScoreQuery:score中构造FixedBitSet对象

        PointValues values = reader.getPointValues(field);
        if (values == null) {
          return null;
        }

        FixedBitSet result = new FixedBitSet(reader.maxDoc());
        float[] scores = new float[reader.maxDoc()];
        values.intersect(new MergePointVisitor(sortedPackedPoints, result, scores));

      @Override
      public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException {
        final ScorerSupplier indexScorerSupplier = indexWeight.scorerSupplier(context);
        final ScorerSupplier dvScorerSupplier = dvWeight.scorerSupplier(context);
        if (indexScorerSupplier == null || dvScorerSupplier == null) {
          return null;
        }
        return new ScorerSupplier() {
          @Override
          public Scorer get(long leadCost) throws IOException {
            // At equal costs, doc values tend to be worse than points since they
            // still need to perform one comparison per document while points can
            // do much better than that given how values are organized. So we give
            // an arbitrary 8x penalty to doc values.
            final long threshold = cost() >>> 3;
            if (threshold <= leadCost) {
              return indexScorerSupplier.get(leadCost);
            } else {
              return dvScorerSupplier.get(leadCost);
            }
          }

          @Override
          public long cost() {
            return indexScorerSupplier.cost();
          }
        };
      }
 /**
   * Get an estimate of the {@link Scorer} that would be returned by {@link #get}.
   * This may be a costly operation, so it should only be called if necessary.
   * @see DocIdSetIterator#cost
   */
  public abstract long cost();

Something that is interesting to notice here is that this query planning optimization does not only depend on the fields that are used and their cardinalities, it goes further and estimates the total number of matches for each node of the query tree in order to make good decisions. This means that taking a query and slightly changing the range of values might completely change how the query is executed under the hood.

计算cost的方法

  private long computeCost() {
    OptionalLong minRequiredCost = Stream.concat(
        subs.get(Occur.MUST).stream(),
        subs.get(Occur.FILTER).stream())
        .mapToLong(ScorerSupplier::cost)
        .min();
    if (minRequiredCost.isPresent() && minShouldMatch == 0) {
      return minRequiredCost.getAsLong();
    } else {
      final Collection<ScorerSupplier> optionalScorers = subs.get(Occur.SHOULD);
      final long shouldCost = MinShouldMatchSumScorer.cost(
          optionalScorers.stream().mapToLong(ScorerSupplier::cost),
          optionalScorers.size(), minShouldMatch);
      return Math.min(minRequiredCost.orElse(Long.MAX_VALUE), shouldCost);
    }
  }

参考文档

1. 工作中组内遇到的 elasticsearch 使用上的踩坑总结 - AIQ

2. https://www.elastic.co/cn/blog/better-query-planning-for-range-queries-in-elasticsearch

3. [LUCENE-7055] Better execution path for costly queries - ASF JIRA

4. IndexOrDocValuesQuery-html

张清华bkd选股指标是指张清华在投资领域使用的一套选股指标体系。bkd是他个人研发的一种量化投资策略,通过基于数据分析和统计模型来选择和评估股票投资标的。该指标主要包括以下几个方面: 1. 市场行情分析:张清华bkd选股指标首先会对市场整体的行情进行分析,包括宏观经济情况、行业走势以及市场风险等。通过对整体市场的判断,选择适应当前市场环境的投资策略。 2. 财务数据分析:该指标还会对上市公司的财务报表进行细致的分析,包括收益状况、成本结构、资产负债等指标。通过分析公司的财务数据,判断其盈利能力、成长性以及风险水平。 3. 技术分析:除了财务数据之外,张清华bkd选股指标还会通过技术分析的手段来判断股票的趋势和走势。这包括使用图表、指标和趋势线等工具来分析价格和交易量,进而发现股票的买入和卖出信号。 4. 风险控制:风险是投资过程必须注意的因素之一,张清华bkd选股指标也会对投资标的的风险进行评估和控制。通过设置止损位、合理配置资产等方式来降低投资的风险。 总的来说,张清华bkd选股指标是一套综合考量市场行情、财务数据、技术分析和风险控制的选股策略。这一指标的目的是帮助投资者在股市做出更明智的投资决策,提高投资成功的概率。但需要注意的是,这只是一种投资策略,投资者在使用该指标时还需要结合自身的风险承受能力和投资目标进行综合考量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值