[英]elasticsearch tf-idf and ignoring field length norm in search
您不能基於每個搜索禁用規范,但您可以使用多字段API添加禁用規范的其他字段。
PUT /my_index
{
"mappings": {
"my_type": {
"properties": {
"my_field": {
"type": "string",
"fields": {
"no_norms": {
"type": "string",
"norms": {
"enabled": false
}
}
}
}
}
}
}
}
現在,你可以搜索my_field
如果你需要規范和my_field.no_norms
如果你不這樣做。 您必須重新索引數據,以便新字段可用於所有文檔,只需將其添加到映射中,就不會更改退出文檔的任何內容。
所以這就是我最終使用的方法。 而不是使用tf-idf(當前彈性搜索默認值)我使用了BM25,這應該更好。 此外,它具有參數“b”,表示場長規范的重要性。 對於“b = 0”,忽略字段長度范數,而默認值為0.75。 可在此處找到BM25的討論。 我的elasticsearch.yml里面有
index :
similarity:
default:
type: BM25
b: 0.0
k1: 1.2
norm_bm25:
type: BM25
b: 0.75
k1: 1.2
對於那些使用elasticsearch javascript api的人,可以在索引創建期間定義自定義相似性
client.indices.create({
index: "db",
body: {
settings: {
number_of_shards: 1,
similarity : "norm_bm25"
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.