我目前正在为 Elasticsearch 使用 Java API。
建议查询返回多个结果“建议”,我希望能够对其进行迭代并访问变量。这是通过以下方式完成的:
val builder = es.prepareSuggest("companies").addSuggestion(new CompletionSuggestionBuilder("companies").field("name_suggest").text(text).size(count()) )
val suggestResponse = builder.execute().actionGet()
val it = suggestResponse.getSuggest.iterator()
现在
while (it.hasNext()){
val info = it.next()
info.....
}
我需要能够从“信息”的有效载荷中访问信息。返回的示例如下所示:
{
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"companies": [
{
"text": "wells",
"offset": 0,
"length": 16,
"options": [
{
"text": "Wells Fargo",
"score": 123.0,
"payload": {
"industry_id": 130,
"id": 776,
"popularity": 123
}
},
{
"text": "Wells Real Estate Funds",
"score": 140.0,
"payload": {
"industry_id": 100,
"id": 778,
"popularity": 123
}
},
{
"text": "Wellstar Health System",
"score": 126.0,
"payload": {
"industry_id": 19,
"id": 1964,
"popularity": 123
}
}
]
}
]
}
在遍历每个建议时,我似乎无法获得有效载荷。关于我如何做到这一点的任何想法?