原生rest:
對“不好”進行分詞, "operator": "and"
意思是同時滿足。
POST corpus_details_22/_search
{
"query": {
"dis_max": {
"queries": [
{
"match": {
"sourceContent": {
"query": "不好",
"operator": "and"
}
}
}
]
}
}
}
結果:文章來源:http://www.zghlxwxcb.cn/news/detail-512975.html
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 2.4820914,
"hits" : [
{
"_index" : "corpus_details_22",
"_type" : "_doc",
"_id" : "gqYAxYMBXTGsShgCkhpA",
"_score" : 2.4820914,
"_source" : {
"targetContent" : "haobuhao .",
"sourceContent" : "好不好。",
"realmCode" : 0,
"sourceLanguageId" : 1,
"corpusScore" : 1,
"id" : 5,
"targetLanguageId" : 2
}
},
{
"_index" : "corpus_details_22",
"_type" : "_doc",
"_id" : "g6YAxYMBXTGsShgCkhqB",
"_score" : 2.2032433,
"_source" : {
"targetContent" : "nibuhao .",
"sourceContent" : "你不好。",
"realmCode" : 0,
"sourceLanguageId" : 1,
"corpusScore" : 0.4,
"id" : 6,
"targetLanguageId" : 2
}
},
{
"_index" : "corpus_details_22",
"_type" : "_doc",
"_id" : "gKYAxYMBXTGsShgCkRq5",
"_score" : 1.9686708,
"_source" : {
"targetContent" : "not very good .",
"sourceContent" : "不怎么好。",
"realmCode" : 0,
"sourceLanguageId" : 1,
"corpusScore" : 1,
"id" : 3,
"targetLanguageId" : 2
}
}
]
}
}
java RestHighLevelClient文章來源地址http://www.zghlxwxcb.cn/news/detail-512975.html
public CorpusDetailsLikesVo getLikesData(String indexName, String target) throws IOException {
RestHighLevelClient client = RestHighLevelClientPoolUtil.getClient();
SearchRequest request = new SearchRequest(indexName);
SearchSourceBuilder builder = new SearchSourceBuilder();
DisMaxQueryBuilder disMaxQuery = QueryBuilders.disMaxQuery();
// 復合查詢
disMaxQuery.innerQueries().add(
QueryBuilders.matchQuery(
"sourceContent", target
).operator(Operator.AND)
);
// 組裝查詢條件
builder.query(disMaxQuery);
// 返回數(shù)據(jù)
request.source(builder);
SearchResponse response = client.search(request, RequestOptions.DEFAULT);
for (SearchHit hit : response.getHits().getHits()) {
Map<String, Object> sourceAsMap = hit.getSourceAsMap();
if (!sourceAsMap.isEmpty()) {
Object res = BeanUtil.mapToBean(sourceAsMap, Object.class, false);
}
}
client.close();
}
到了這里,關于es最大相似度檢索(原生與java客戶端)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!