【问题标题】:Elasticsearch: Expected field name but got START_OBJECTElasticsearch:预期的字段名称,但得到 START_OBJECT
【发布时间】:2015-05-26 19:38:31
【问题描述】:

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

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"
    }
  }
}

【问题讨论】:

    标签: json elasticsearch


    【解决方案1】:

    您的 field_value_factor 函数放错了位置。它应该是nested within the functions property。试试这个查询

    {
      "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": {}
                  }
                }
              ]
            }
          }
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      您的查询有误,field_value_factor 是 function_score 的 n 属性:

      {
        "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"
            }
          }
        }
      }
      

      因为你只有一个函数,你不需要把它嵌套到“函数”中

      【讨论】:

      • 啊,非常感谢!它现在没有给出任何错误,但是有什么方法可以将 thread_name 结果和 message_text 结果分开。一旦我输入函数分数,结果就会好坏参半,首先返回 message_text,因为它比线程标题中带有关键字的结果更受欢迎
      • 不,你不能在单个查询中做这样的事情,但你可以在其中一个字段上使用提升来确保该字段的结果始终是第一个。
      猜你喜欢
      • 1970-01-01
      • 2016-07-28
      • 1970-01-01
      • 2013-03-27
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 2022-08-14
      • 2020-06-28
      相关资源
      最近更新 更多