Java Code Examples for org.elasticsearch.index.query.QueryBuilders#regexpQuery()
The following examples show how to use
org.elasticsearch.index.query.QueryBuilders#regexpQuery() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestController.java From SpringBootLearn with Apache License 2.0 | 5 votes |
/** * 正则查询 * @return */ @GetMapping("/queryRegexpData") public String queryRegexpData() { QueryBuilder queryBuilder = QueryBuilders.regexpQuery("name.keyword", "书名[0-9]{1,7}"); List<Map<String, Object>> list = ElasticsearchUtil.searchListData(indexName, esType, queryBuilder, 10, null, null, null); return JSONObject.toJSONString(list); }
Example 2
Source File: ElasticSearchHelper.java From sunbird-lms-service with MIT License | 5 votes |
/** * This method create lexical query with boosts if any provided * * @param key for search * @param rangeOperation to search or match in a particular way * @param boost for increasing the search parameters priority * @return QueryBuilder */ public static QueryBuilder createLexicalQuery( String key, Map<String, Object> rangeOperation, Float boost) { QueryBuilder queryBuilder = null; for (Map.Entry<String, Object> it : rangeOperation.entrySet()) { switch (it.getKey()) { case STARTS_WITH: { String startsWithVal = (String) it.getValue(); if (StringUtils.isNotBlank(startsWithVal)) { startsWithVal = startsWithVal.toLowerCase(); } if (isNotNull(boost)) { queryBuilder = QueryBuilders.prefixQuery(key + RAW_APPEND, startsWithVal).boost(boost); } queryBuilder = QueryBuilders.prefixQuery(key + RAW_APPEND, startsWithVal); break; } case ENDS_WITH: { String endsWithRegex = "~" + it.getValue(); if (isNotNull(boost)) { queryBuilder = QueryBuilders.regexpQuery(key + RAW_APPEND, endsWithRegex).boost(boost); } queryBuilder = QueryBuilders.regexpQuery(key + RAW_APPEND, endsWithRegex); break; } } } return queryBuilder; }
Example 3
Source File: RegexpQueryDemo.java From elasticsearch-full with Apache License 2.0 | 5 votes |
@Test public void testForClient() throws Exception { QueryBuilder qb = QueryBuilders.regexpQuery( "name.first", "s.*y"); client.prepareSearch().setQuery(qb).execute().actionGet(); }
Example 4
Source File: ElasticsearchAnySearchDAO.java From syncope with Apache License 2.0 | 4 votes |
private static QueryBuilder fillAttrQuery( final PlainSchema schema, final PlainAttrValue attrValue, final AttrCond cond) { Object value = schema.getType() == AttrSchemaType.Date && attrValue.getDateValue() != null ? attrValue.getDateValue().getTime() : attrValue.getValue(); QueryBuilder builder = EMPTY_QUERY_BUILDER; switch (cond.getType()) { case ISNOTNULL: builder = QueryBuilders.existsQuery(schema.getKey()); break; case ISNULL: builder = QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(schema.getKey())); break; case ILIKE: StringBuilder output = new StringBuilder(); for (char c : cond.getExpression().toLowerCase().toCharArray()) { if (c == '%') { output.append(".*"); } else if (Character.isLetter(c)) { output.append('['). append(c). append(Character.toUpperCase(c)). append(']'); } else { output.append(c); } } builder = QueryBuilders.regexpQuery(schema.getKey(), output.toString()); break; case LIKE: builder = QueryBuilders.wildcardQuery(schema.getKey(), cond.getExpression().replace('%', '*')); break; case IEQ: builder = QueryBuilders.matchQuery(schema.getKey(), cond.getExpression().toLowerCase()); break; case EQ: builder = QueryBuilders.termQuery(schema.getKey(), value); break; case GE: builder = QueryBuilders.rangeQuery(schema.getKey()).gte(value); break; case GT: builder = QueryBuilders.rangeQuery(schema.getKey()).gt(value); break; case LE: builder = QueryBuilders.rangeQuery(schema.getKey()).lte(value); break; case LT: builder = QueryBuilders.rangeQuery(schema.getKey()).lt(value); break; default: } return builder; }
Example 5
Source File: EsAbstractConditionQuery.java From fess with Apache License 2.0 | 4 votes |
protected RegexpQueryBuilder regRegexpQ(String name, String regexp) { checkEsInvalidQuery(name, regexp); RegexpQueryBuilder regexpQuery = QueryBuilders.regexpQuery(name, regexp); regQ(regexpQuery); return regexpQuery; }
Example 6
Source File: EsAbstractConditionQuery.java From fess with Apache License 2.0 | 4 votes |
protected RegexpQueryBuilder regRegexpQ(String name, String regexp) { checkEsInvalidQuery(name, regexp); RegexpQueryBuilder regexpQuery = QueryBuilders.regexpQuery(name, regexp); regQ(regexpQuery); return regexpQuery; }
Example 7
Source File: EsAbstractConditionQuery.java From fess with Apache License 2.0 | 4 votes |
protected RegexpQueryBuilder regRegexpQ(String name, String regexp) { checkEsInvalidQuery(name, regexp); RegexpQueryBuilder regexpQuery = QueryBuilders.regexpQuery(name, regexp); regQ(regexpQuery); return regexpQuery; }