Json Elasticsearch:应为字段名,但获得了START\u对象
我一直在尝试运行以下查询,但每次运行时都会收到以下错误:Json Elasticsearch:应为字段名,但获得了START\u对象,json,
elasticsearch,Json,
elasticsearch,我一直在尝试运行以下查询,但每次运行时都会收到以下错误: nested: ElasticsearchParseException[Expected field name but got START_OBJECT \"field_value_factor\"]; }]","status":400 以下是查询: { "query": { "function_score": { "query": { "bool": { "should":
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"
}
}
}
您的
字段\u值\u因子
函数放错了位置。应该是。请尝试此查询
{
"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": {}
}
}
]
}
}
}
}
}
您的查询中有一个错误,
字段\u值\u因子
是函数\u分数的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"
}
}
}
}
因为您只有一个函数,所以不需要将其嵌套到“函数”中。啊,非常感谢!它现在没有给出任何错误,但是有没有办法将线程名称结果和消息文本结果分开。一旦我输入函数分数,结果就会混合,首先返回消息\文本,因为它比线程标题中带有关键字的结果更受欢迎。你不能在一个查询中做这样的事情,但你可以对其中一个字段进行增强,以确保此字段的结果始终是第一位的。