是否可以在 Elasticsearch 中结合使用 _msearch 和建议者?

Is it possible to combine _msearch and a suggester in Elasticsearch?

我正在尝试捆绑 multi search api with a term suggester

当我尝试在搜索端点上使用建议器时,它起作用了:

POST my-index-000001/_search
{
  "query" : {
    "match": {
      "message": "tring out Elasticsearch"
    }
  },
  "suggest" : {
    "my-suggestion" : {
      "text" : "tring out Elasticsearch",
      "term" : {
        "field" : "message"
      }
    }
  }
}

以下是尝试对多重搜索执行相同操作的方法:

GET my-index-000001/_msearch
{ }
{
  "query" : {
    "match": {
      "message": "tring out Elasticsearch"
    }
  },
  "suggest" : {
    "my-suggestion" : {
      "text" : "tring out Elasticsearch",
      "term" : {
        "field" : "message"
      }
    }
  }
}
{"index": "my-index-000002"}
{"query" : {"match_all" : {}}}

结果,我得到一个错误:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "json_e_o_f_exception",
        "reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: (org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 1, column: 1])\n at [Source: (org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 1, column: 2]"
      }
    ],
    "type" : "json_e_o_f_exception",
    "reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: (org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 1, column: 1])\n at [Source: (org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper); line: 1, column: 2]"
  },
  "status" : 400
}

所以我的问题是,这可能吗?

我发现了一个类似名称的问题(Using Nest Phrase Suggester on MultiSearch query), but the question itself appears to be about multi-match queries,不是多搜索。

我使用的版本是7.13。

您的查询在语法上是正确的,但多重搜索 API (_msearch) 仅支持 newline-delimited json payloads (ndjson)。

因此,只有在将负载 header 与负载 body:

分开时才会出现换行符 (\n)
header\n
body\n
header\n
body\n
...

因此,请调整您的换行符以符合所需的结构:

GET my-index-000001/_msearch
{}
{"query":{"match":{"message":"tring out Elasticsearch"}},"suggest":{"my-suggestion":{"text":"tring out Elasticsearch","term":{"field":"message"}}}}
{"index":"my-index-000002"}
{"query":{"match_all":{}}}

提示:如果您使用的是 Kibana(看起来您是),您可以使用 +[=24 在扩展模式和 _msearch-valid 模式之间切换=]i / ctrl+i.