Elasticsearch查询最短匹配

时间:2018-11-26 04:20:45

标签: elasticsearch

我在elasticsearch中搜索“ AB”

结果:“ ABB”位于“ AB”前面(得分ABB> AB)

我想要“ AB”>“ ABB”

{
    'sort': [{'_score': {'order': 'desc'}}],
    'from': _from,
    'size': page_size,
    'query': {
        "multi_match": {
            "query": key,
            "type": "best_fields",
            "fields": ["name^5", "intro"]
        }
    }
}

"mappings": {
    "doc": {
        "properties": {

            "intro": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                }
            },
           "name": {
               "type": "text",
               "fields": {
                   "keyword": {
                       "ignore_above": 256,
                       "type": "keyword"
                   }
               }
           },
           "id": {
               "type": "long"
           },
        }
    }
}

我的数据是中文

例如:     名称:刘佳简介:“ xxxxxx”     名称:刘佳佳简介:“ xxxxxx”

1 个答案:

答案 0 :(得分:1)

如果您的语料库中的ABB比AB少,那么ABB的得分会更高,因为默认评分使用TF / IDF公式。

如果要基于字段长度将字段增加查询时间,则首先需要将字段长度存储在另一个字段中(使用无痛的管道操作或在对数据进行索引之前)。然后,您将可以使用带有log2p修饰符的function_score_query(请参阅此处field value factor function)来计算字段长度

相关问题