简体   繁体   English

带有匹配词组(精确搜索)子句的Elasticsearch Java API Boost查询

[英]Elasticsearch Java API Boost query with Match Phrase (Exact Search) Clause

My end goal is to perform exact search on a phrase entered (Example: Test Type Search) and boosting the result if say the exact phrase matches to the column that I am looking for. 我的最终目标是对输入的短语进行精确搜索(例如:测试类型搜索),如果说出准确的短语与我要查找的列匹配,则提高结果。

I am using the the Elasticsearch Java APIs for this. 我正在为此使用Elasticsearch Java API。 Please find the code as below, 请找到以下代码,

QueryBuilder queryBuilder = QueryBuilders.matchPhraseQuery("_all", "Test Type Search");

SearchResponse response = client.prepareSearch("index_name")
                        .setQuery(queryBuilder)
                        .setFrom(1)
                        .setSize(10)
                        .execute()
                        .actionGet();

I would like to know how to boost a field in the index that contains this exact value. 我想知道如何在包含此确切值的索引中增强字段。

The above response also returns responses that has values say, "Test code is used for this Type of Search" and not exactly "Test Type Search". 上面的响应还返回具有以下值的响应:“测试代码用于此搜索类型”,而并非完全是“测试类型搜索”。 How can I rectify this? 我该如何纠正?

Is there a way I can find proper Elasticsearch Java API documentation (2.0.0)? 有什么方法可以找到正确的Elasticsearch Java API文档(2.0.0)?

From your question it looks like you want to match whole term(value) only ie "Test Type Search". 从您的问题看来,您只想匹配整个术语(值),即“测试类型搜索”。
For this you can use QueryBuilders.termQuery(field, value) and for matching terms, use QueryBuilders.matchQuery(field, value) 为此,您可以使用QueryBuilders.termQuery(field,value) ,对于匹配术语,请使用QueryBuilders.matchQuery(field,value)
wherein field : your doc field on which you want to query value : what exactly you want to match. 其中field:您要查询的文档字段value:您要完全匹配的内容。

Refer ES Doc 请参阅ES Doc
Refer ES Java API Doc 请参阅ES Java API 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM