0
我正在使用以下函数来获取某些ID集的术语向量。Elasticsearch Java中的MultiTermVectors
public static void builtTermVectorRequest(Client client, String index, Map<String, String> postIDs) {
TermVectorsRequest termVectorsRequest = new TermVectorsRequest();
termVectorsRequest.index(index).type("post");
for (Map.Entry<String, String> entry : postIDs.entrySet()) {
String currentPostId = entry.getKey();
String currentParentID = entry.getValue();
termVectorsRequest
.id(currentPostId)
.parent(currentParentID)
.termStatistics(true)
.selectedFields("content");
}
MultiTermVectorsRequestBuilder mtbuilder = client.prepareMultiTermVectors();
mtbuilder.add(termVectorsRequest);
MultiTermVectorsResponse response = mtbuilder.execute().actionGet();
XContentBuilder builder;
try {
builder = XContentFactory.jsonBuilder().startObject();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
System.out.println(builder.prettyPrint().string());
} catch (IOException e) {}
}
在这里我有一些文件ID连同他们的父母ID作为文件是子文件。
我得知即使它们存在,文档也没有找到。
为了证实我尝试使用Python中同样的事情:
body = dict(docs=map(lambda x:
{
"fields": ["content"],
"_id": x["_id"],
"_routing": x["_routing"],
"term_statistics": "true"
}, result["hits"]["hits"]))
es_client = elasticsearch.Elasticsearch([{'host': '192.168.111.12', 'port': 9200}])
all_term_vectors = es_client.mtermvectors(
index="prf_test",
doc_type="post",
body=body
)
,我得到返回结果。
Java代码有什么问题?
看起来有些'routing'问题是'X [“_路由”]'一样ParentId如果是的话,你可以明确地尝试'.routing(currentParentID)'? – keety
做了这项工作? – keety
@ keety对不起,没跟进。即使在我尝试了更多组合并最终实现它的工作之后,我也遇到了同样的问题。你可以查看我的答案。 –