【问题标题】:What is the difference between span_containing and span_within query in elasticsearch?elasticsearch中的span_containing和span_within查询有什么区别?
【发布时间】:2019-02-15 00:05:02
【问题描述】:

文档说

跨度包含:

big 和 little 子句可以是任何 span 类型的查询。匹配跨度 包含来自 little 的匹配项的 from big 将被返回。

span_within:

big 和 little 子句可以是任何 span 类型的查询。匹配跨度 from little 包含在 big 中的返回。

【问题讨论】:

    标签: elasticsearch lucene search-engine querydsl


    【解决方案1】:

    就查询匹配哪些文档而言,没有区别。区别在于匹配的是哪个跨度。

    • span_containing 匹配大。
    • span_within 匹配很少。

    查询将从匹配的 span 中获取提升,因此 span_contain 将从 big 中获取提升,而 span_within 将从匹配的 little 中获取提升。

    如果您的 span_within 或 span_ contains 是另一个 span 查询的一部分,该查询考虑了匹配 span 的位置,则差异也会变得相关。


    例如,假设您有一些文本:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.

    并且您的 span_ contains/within 与前五个术语匹配,几乎没有匹配“ipsum”。如果您随后将其包装在 span_near 中,则该外部 span_near 的斜率将从 big 的边界获取 span_containing,以及从 little ("ipsum") 的边界获取 span_within。

    “amet”(big 的结尾)和“consectetur”之间的距离≤1,所以这个会匹配文本:

    "span_near": {
      "clauses": [
        "span_containing" : {
          "little" : {
            "span_term" : { "field" : "ipsum" }
          },
          "big" : {
            "span_near" : {
              "clauses" : [
                { "span_term" : { "field" : "lorem" } },
                { "span_term" : { "field" : "amet" } }
              ],
              "slop" : 5,
              "in_order" : true
            }
          }
        },
        { "span_term" : { "field" : "consectetur" } }
      ],
      "slop": 1,
      "in_order": true
    }
    

    但是“ipsum”和“consectetur”之间的距离是>1,所以这个不会

    "span_near": {
      "clauses": [
        "span_within" : {
          "little" : {
            "span_term" : { "field" : "ipsum" }
          },
          "big" : {
            "span_near" : {
              "clauses" : [
                { "span_term" : { "field" : "lorem" } },
                { "span_term" : { "field" : "amet" } }
              ],
              "slop" : 5,
              "in_order" : true
            }
          }
        },
        { "span_term" : { "field" : "consectetur" } }
      ],
      "slop": 1,
      "in_order": true
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-03
      • 2021-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 1970-01-01
      相关资源
      最近更新 更多