原生rest:
对“不好”进行分词, "operator": "and"
意思是同时满足。
POST corpus_details_22/_search
{
"query": {
"dis_max": {
"queries": [
{
"match": {
"sourceContent": {
"query": "不好",
"operator": "and"
}
}
}
]
}
}
}
结果:文章来源:https://www.toymoban.com/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文章来源地址https://www.toymoban.com/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);
// 返回数据
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客户端)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!