elasticsearch中格式错误的查询异常

时间:2015-05-22 10:04:40

标签: java elasticsearch

我正在尝试在elasticsearch中使用field_value_factor函数,这是我第一次使用它并且我遇到了一些奇怪的错误。

以下是搜索查询,关键字变量也会传递给搜索查询所属的方法:

{"function_score": 
{"functions": ["field_value_factor": 
    {"field" : "thread_view", 
    "factor": 1.2, 
    "modifier" : "sqrt"}], 
    {"bool": 
        {"should": 
            [{"match": 
                {"thread_name": " + keyword + "}}, 
                    {"nested": 
                        {"path": 
                            "messages","query": 
                                {"bool": 
                                    {"should": 
                                        [{"match": 
                                            {"messages.message_text": " + keyword + "}
                                        }]
                                    }
                                }, 
                            "inner_hits": {}
                        }
                    }]
                }
            }, 
        "score_mode": "multiply"
    }
}

以下是我收到的错误:

nested: QueryParsingException[[thread_and_messages] function_score: malformed query, expected a START_OBJECT while parsing functions but got a VALUE_STRING];

1 个答案:

答案 0 :(得分:0)

试试这个:

{
  "query": {
    "function_score": {
      "functions": [
        {
          "field_value_factor": {
            "field": "thread_view",
            "factor": 1.2,
            "modifier": "sqrt"
          }
        }
      ],
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "thread_name": " + keyword + "
              }
            },
            {
              "nested": {
                "path": "messages",
                "query": {
                  "bool": {
                    "should": [
                      {
                        "match": {
                          "messages.message_text": " + keyword + "
                        }
                      }
                    ]
                  }
                },
                "inner_hits": {}
              }
            }
          ]
        }
      },
      "score_mode": "multiply"
    }
  }
}