我正在 elastic search 进行 function_score 查询 .

查询的提升权重是临时确定的(并且在用户之间不同) . 此外,根据上下文,查询的术语在用户之间会有所不同 . 示例查询可能如下所示:

{
  "query": {
    "function_score": {
      "filter": { 
        "term": { "in_stock": true },
        ... more filters ...
      },
      "functions": [
        {
          "filter": { "term": { "color": "red" }}, 
          "weight": 2
        },
        {
          "filter": { "term": { "style": "elegant" }}, 
          "weight": 1
        },
        {
          "filter": { "term": { "length": "long" }}, 
          "weight": 3 
        }
      ],
      "score_mode": "sum", 
    }
  }
}

The document is simple and looks along the lines of:


{
  "product_id" : "abc",
  "name" : "blah blah",
  "price" : 10
  "in_stock" : true,
  "color: "red",
  "style" : "elegant",
  "length" : "long",
  ... more attributes...

}

已过滤术语的映射类型为 keywordsboolean . 在任何地方都没有做任何自由文本 .

在索引大小变大(索引中大约100万个文档)之前,查询性能是合理的 . 此时,查询将需要几秒钟才能完成 .

索引配置:

我玩过限制碎片大小,目前碎片限制在100万件,因为之后性能似乎变得更糟 . 复制位于5.索引是只读的 .

由于查询之间的权重和术语会有所不同,我不确定是否可以以加快查询速度的方式对索引进行预排序 .

我不确定弹性搜索如何在加权查询的情况下缓存结果,得分和排序 .