elasticsearch中的field_value_factor的多个输入

时间:2017-04-18 22:10:56

标签: elasticsearch elasticsearch-dsl

我正在尝试使用field_value_factor来制定弹性搜索查询来衡量文档中的某些字段。

{
  "query": {
    "match": {
      "local": true
    },
    "function_score": {
      "functions": [
        {
          "field_value_factor": {
            "field": "title",
            "factor": 1.2,
            "missing": 1
          }
        },
        {
          "gauss": {
            "location": {
              "origin": {
                "lat": 51.5,
                "lon": 0.12
              },
              "offset": "2 Miles",
              "scale": "3 Miles"
            }
          }
        },
        {
          "gauss": {
            "creation_time": {
              "decay": 0.8,
              "offset": "2d",
              "scale": "48d"
            }
          },
          "weight": 2
        }
      ]
    }
  }
}

任何输入,例如:

"field_value_factor": {
                             "field": [“title”,"description"],
                             "factor": [1.2,0.8],
                             "missing": [1,0]
                            }

不适用于这两个字段,查询检索与第一个文档相同的文档。

是否可以在“field_value_vector”中输入多个术语?

1 个答案:

答案 0 :(得分:3)

您可以使用多个field_value_factor函数,每个字段一个

{
  "query": {
    "match": {
      "local": true
    },
    "function_score": {
      "functions": [
        {
          "field_value_factor": {
            "field": "title",
            "factor": 1.2,
            "missing": 1
          }
        },
        {
          "field_value_factor": {
            "field": "description",
            "factor": 0.8,
            "missing": 0
          }
        },
        {
          "gauss": {
            "location": {
              "origin": {
                "lat": 51.5,
                "lon": 0.12
              },
              "offset": "2 Miles",
              "scale": "3 Miles"
            }
          }
        },
        {
          "gauss": {
            "creation_time": {
              "decay": 0.8,
              "offset": "2d",
              "scale": "48d"
            }
          },
          "weight": 2
        }
      ]
    }
  }
}