【问题标题】:elasticsearch 1.6 field norm calculation with shingle filterelasticsearch 1.6 带瓦过滤器的场范数计算
【发布时间】:2015-06-29 22:54:41
【问题描述】:

我正在尝试了解 elasticsearch (1.6) 中使用 shingle 分析器索引的文档的 fieldnorm 计算 - 它似乎不包括 shingled 术语。如果是这样,是否可以将计算配置为包括叠瓦项?具体来说,这是我使用的分析器:

{
  "index" : {
    "analysis" : {
        "filter" : {
            "shingle_filter" : {
                "type" : "shingle",
                "max_shingle_size" : 3
            }
        },
        "analyzer" : {
            "my_analyzer" : {
                "type" : "custom",
                "tokenizer" : "standard",
                "filter" : ["word_delimiter", "lowercase", "shingle_filter"]
            }
        }  
    }
 }

}

这是使用的映射:

{
    "docs": {
        "properties": {
            "text" : {"type": "string", "analyzer" : "my_analyzer"}
        }
    }
}

我发布了一些文件:

{"text" : "the"}
{"text" : "the quick"}
{"text" : "the quick brown"}
{"text" : "the quick brown fox jumps"}
...

将以下查询与解释 API 一起使用时,

{
    "query": {
        "match": {
            "text" : "the"
        }
    }
}

我得到以下字段规范(为简洁起见,省略了其他细节):

"_source": {
    "text": "the quick"
},
"_explanation": {
    "value": 0.625,
    "description": "fieldNorm(doc=0)"
}

"_source": {
    "text": "the quick brown fox jumps over the"
},
"_explanation": {
    "value": 0.375,
    "description": "fieldNorm(doc=0)"
}

这些值似乎表明 ES 看到 2 个术语用于第一个文档(“the quick”)和 7 个术语用于第二个文档(“the quick brown fox jumps over the”),不包括带状疱疹。是否可以将 ES 配置为也使用 shingled 术语(即分析器返回的所有术语)计算字段规范?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您需要通过禁用折扣重叠标志来自定义default similarity

    例子:

    {
      "index" : {
          "similarity" : {
              "no_overlap" : {
                "type" : "default",
                "discount_overlaps" : false
              } 
        },
        "analysis" : {
            "filter" : {
                "shingle_filter" : {
                    "type" : "shingle",
                    "max_shingle_size" : 3
                }
            },
            "analyzer" : {
                "my_analyzer" : {
                    "type" : "custom",
                    "tokenizer" : "standard",
                    "filter" : ["word_delimiter", "lowercase", "shingle_filter"]
                }
            }  
        }
     }
    }
    

    映射:

    {
        "docs": {
            "properties": {
                "text" : {"type": "string", "analyzer" : "my_analyzer", "similarity
    " : "no_overlap"}
            }
        }
    }
    

    进一步扩展:

    默认情况下重叠,即在计算规范时忽略位置增量为 0 的标记

    下面的示例显示了由 OP 中描述的“my_analyzer”生成的令牌位置:

    get <index_name>/_analyze?field=text&text=the quick
    
    {
       "tokens": [
          {
             "token": "the",
             "start_offset": 0,
             "end_offset": 3,
             "type": "<ALPHANUM>",
             "position": 1
          },
          {
             "token": "the quick",
             "start_offset": 0,
             "end_offset": 9,
             "type": "shingle",
             "position": 1
          },
          {
             "token": "quick",
             "start_offset": 4,
             "end_offset": 9,
             "type": "<ALPHANUM>",
             "position": 2
          }
       ]
    }
    

    根据lucene documentation,默认相似度的长度范数计算实现如下:

    state.getBoost()*lengthNorm(numTerms)
    

    numTerms

    if setDiscountOverlaps(boolean) is false
      FieldInvertState.getLength() 
    else 
       FieldInvertState.getLength() - FieldInvertState.getNumOverlap()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多