我正在尝试将此查询转换为java代码(HighLevelRestClient):
{
"query":{
"bool": {
"must": [
{
"query_string": {
"query": "((\"PUT\" OR \"POST\") AND \"REST\" AND (\"BRI\" OR \"BRIEXT\" OR \"TMP\"))"
}
}
]
}
}
}
我用邮递员尝试了这个请求,它工作正常,我想用elasticSearch resthighlevel客户端尝试。
QueryBuilder matchQueryBuilder = QueryBuilders.boolQuery().must();
我不知道要把什么放在里面。
有人可以帮我这个吗?
答案 0 :(得分:0)
您可以使用queryStringQuery
String query = "((\"PUT\" OR \"POST\") AND \"REST\" AND (\"BRI\" OR
\"BRIEXT\" OR \"TMP\"))";
QueryBuilder matchQueryBuilder = QueryBuilders.boolQuery().must(new
QueryStringQueryBuilder(query));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(matchQueryBuilder);
SearchRequest searchRequest = new SearchRequest();
// set the indices you want to search in.
searchRequest.indices("your-index");
searchRequest.source(searchSourceBuilder);
// execute the query
SearchResponse response = hlRestClient.search(searchRequest, header);
SearchHits hits = response.getHits();
方法
以下代码段使用official documentation
<?php
function paginated_category( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_category() ) {
$query->set( 'posts_per_page', 2 );
}
}
}
add_action( 'pre_get_posts', 'paginated_category' );
?>