标签:单词 pre ctr wildcard card type 匹配 dsquery 分词
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
QueryBuilder queryBuilder = QueryBuilders.termQuery("字段","term值"); SearchResponse response = client.prepareSearch("索引名称").setTypes("type名称").setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(queryBuilder).execute().actionGet(); //获取命中数 System.out.println(response.getHits().totalHits()); //获取响应字符串 System.out.println(response.toString()); //遍历查询结果输出相关度分值和文档内容 SearchHits searchHits = response.getHits(); for(SearchHit searchHit : searchHits){ System.out.println(searchHit.getScore()); System.out.println(searchHit.getSourceAsString()); }
查询hotelName 分词后包含 hotel的term的文档
QueryBuilders.termQuery("hotelName","hotel")
查询hotelName 包含 hotel 或test 中的任何一个或多个的文档
QueryBuilders.termsQuery("hotelName","hotel","test")
QueryBuilders.rangeQuery("hotelNo").gt("10143262306"); //大于 10143262306
QueryBuilders.rangeQuery("hotelNo").lt("101432623062055348221"); //小于 101432623062055348221
QueryBuilders.rangeQuery("hotelNo").includeLower(true); //包括下界
QueryBuilders.rangeQuery("hotelNo").includeUpper(false); //包括上界
查询字段address 不为null的数据
QueryBuilders.existsQuery("address")
java client 该方法已经标记为过时,推荐用exist代替 如下
existsQuery BoolQueryBuilder#mustNot(QueryBuilder)
QueryBuilders.missingQuery("accountGuid") 等同 QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery("accountGuid"));
如果字段没分词,就匹配整个字段前缀
QueryBuilders.prefixQuery("hotelName","花园")
支持* 任意字符串;?任意一个字符
QueryBuilders.wildcardQuery("channelCode","ctr*")
QueryBuilders.wildcardQuery("channelCode","ctr?")
正则表达式自己写吧 略
通过增加fuzziness 模糊属性,来查询term 如下 能够匹配 hotelName 为 te el tel前或后加一个字母的term的 文档 fuzziness 的含义是检索的term 前后增加或减少n个单词的匹配查询
QueryBuilders.fuzzyQuery("hotelName", "tel").fuzziness(Fuzziness.ONE)
英文原文:Filters documents matching the provided document / mapping type.
QueryBuilders.typeQuery("channelCode")
QueryBuilders.idsQuery().addIds("exchange_operate_monitor_db$32293","exchange_operate_monitor_db$32294")
标签:单词 pre ctr wildcard card type 匹配 dsquery 分词
原文地址:https://www.cnblogs.com/diandianquanquan/p/11219219.html