elasticsearch:需要字段名,但得到start\u对象

daolsyd0  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(2)|浏览(287)

我一直在尝试运行以下查询,但每次运行时都会收到以下错误:

nested: ElasticsearchParseException[Expected field name but got START_OBJECT \"field_value_factor\"]; }]","status":400

以下是查询:

{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "should": [{
            "match": {
              "thread_name": "parenting"
            }
          }, {
            "nested": {
              "path": "messages",
              "query": {
                "bool": {
                  "should": [{
                    "match": {
                      "messages.message_text": "parenting"
                    }
                  }]
                }
              },
              "inner_hits": {}
            }
          }]
        }
      }
    },
    "field_value_factor": {
      "field": "thread_view"
    }
  }
}
mklgxw1f

mklgxw1f1#

你的 field_value_factor 功能错位。它应该嵌套在 functions 财产。请改为尝试此查询

{
  "query": {
    "function_score": {
      "functions": [
        {
          "field_value_factor": {
            "field": "thread_view"
          }
        }
      ],
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "thread_name": "parenting"
              }
            },
            {
              "nested": {
                "path": "messages",
                "query": {
                  "bool": {
                    "should": [
                      {
                        "match": {
                          "messages.message_text": "parenting"
                        }
                      }
                    ]
                  }
                },
                "inner_hits": {}
              }
            }
          ]
        }
      }
    }
  }
}
cwtwac6a

cwtwac6a2#

你的查询有错误, field_value_factor 是函数的n属性\u分数:

{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "should": [{
            "match": {
              "thread_name": "parenting"
            }
          }, {
            "nested": {
              "path": "messages",
              "query": {
                "bool": {
                  "should": [{
                    "match": {
                      "messages.message_text": "parenting"
                    }
                  }]
                }
              },
              "inner_hits": {}
            }
          }]
        }
      },
      "field_value_factor": {
        "field": "thread_view"
      }
    }
  }
}

因为只有一个函数,所以不需要将其嵌套到“函数”中

相关问题