因此,在ES中编写(右)查询并使用sense插件对本地ES安装进行测试之后,我现在面临的问题是:如何使用ES JAVA API从我的代码中执行相同的操作。下面是我要翻译的查询:
{
"size": 5,
"query": {
"multi_match": {
"query": "physics",
"type": "most_fields",
"fields": [
"document.title^10",
"document.title.shingles^2",
"document.title.ngrams",
"person.name^10",
"person.name.shingles^2",
"person.name.ngrams",
"document.topics.name^10",
"document.topics.name.shingles^2",
"document.topics.name.ngrams"
],
"operator": "and"
}
}
}'我知道应该是这样的,但我不太确定:
Node node = nodeBuilder().client(true).node();
Client client = node.client();
SearchResponse response = client.prepareSearch("dlsnew")
.setTypes("person", "document")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.multiMatchQuery("physics",
"document.title^10",
"document.title.shingles^2",
"document.title.ngrams",
"person.name^10",
"person.name.shingles^2",
"person.name.ngrams",
"document.topics.name^10",
"document.topics.name.shingles^2",
"document.topics.name.ngrams"))
.setFrom(0).setSize(5).setExplain(true)
.execute()
.actionGet();
SearchHit[] results = response.getHits().getHits();另外,如何处理查询中的“操作符”和“类型”:“most_fields”部件?
发布于 2016-05-28 18:02:39
你差点就做到了
QueryBuilders.multiMatchQuery("physics",
"document.title^10",
"document.title.shingles^2",
"document.title.ngrams",
"person.name^10",
"person.name.shingles^2",
"person.name.ngrams",
"document.topics.name^10",
"document.topics.name.shingles^2",
"document.topics.name.ngrams")
.operator(MatchQueryBuilder.Operator.AND)
.type(MultiMatchQueryBuilder.Type.MOST_FIELDS);https://stackoverflow.com/questions/37498726
复制相似问题