org.elasticsearch.index.query.MatchQueryBuilder Java Examples

The following examples show how to use org.elasticsearch.index.query.MatchQueryBuilder. 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: EsQueryVistor.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public void visit( ContainsOperand op ) throws NoFullTextIndexException {
    final String name = op.getProperty().getValue().toLowerCase();
    final String value = op.getLiteral().getValue().toString().toLowerCase();


    // or field is just a string that does need a prefix
    if ( value.indexOf( "*" ) != -1 ) {
        final WildcardQueryBuilder wildcardQuery =
                QueryBuilders.wildcardQuery( IndexingUtils.FIELD_STRING_NESTED, value );
        queryBuilders.push( fieldNameTerm( name, wildcardQuery ) );
    }
    else {
        final MatchQueryBuilder termQuery = QueryBuilders.matchQuery( IndexingUtils.FIELD_STRING_NESTED, value );

        queryBuilders.push( fieldNameTerm( name, termQuery ) );
    }


    //no op for filters, push an empty operation

    //TODO, validate this works
    filterBuilders.push( NoOpFilterBuilder.INSTANCE );
}
 
Example #2
Source File: StoredFeatureParserTests.java    From elasticsearch-learning-to-rank with Apache License 2.0 5 votes vote down vote up
public void testParseErrorOnUnknownField() throws IOException {
    String featureString = "{\n" +
            "\"name\":\"testFeature\"," +
            "\"params\":[\"param1\",\"param2\"]," +
            "\"template_language\":\"mustache\",\n" +
            "\n\"bogusField\":\"oops\"," +
            "\"template\": \n" +
            writeAsNonFormattedString(new MatchQueryBuilder("match_field", "match_word")) +
            "}";
    assertThat(expectThrows(ParsingException.class, () -> parse(featureString)).getMessage(),
            containsString("bogusField"));
}
 
Example #3
Source File: ElasticSearcher.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Page<Product> search(String keyword, int pageNum, int pageSize) {

    BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
    boolQueryBuilder.should(new MatchQueryBuilder("title", keyword));
    boolQueryBuilder.should(new MatchQueryBuilder("content", keyword));


    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.from(pageNum * pageSize - pageSize);
    sourceBuilder.size(pageSize);
    sourceBuilder.query(boolQueryBuilder);

    SearchRequest searchRequest = new SearchRequest();
    searchRequest.source(sourceBuilder);
    searchRequest.indices(index);
    searchRequest.types(type);

    try {
        SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
        if (response == null || response.getHits() == null || response.getHits().getTotalHits().value <= 0) {
            return null;
        }

        int total = (int) response.getHits().getTotalHits().value;

        List<Product> products = new ArrayList<>();
        response.getHits().forEach(hit -> {
            Product product = new Product();
            product.put(hit.getSourceAsMap());
            products.add(product);
        });

        return new Page<>(products, pageNum, pageSize, total / pageSize, total);

    } catch (Exception e) {
        LOG.error(e.toString(), e);
    }
    return null;
}
 
Example #4
Source File: BsFileAuthenticationCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setUpdatedTime_Match(Long updatedTime, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("updatedTime", updatedTime);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #5
Source File: BsScheduledJobCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setScriptType_Fuzzy(String scriptType, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regFuzzyQ("scriptType", scriptType);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #6
Source File: BsDataConfigCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setCreatedTime_Match(Long createdTime, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("createdTime", createdTime);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #7
Source File: BsWebConfigCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setDescription_Match(String description, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("description", description);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #8
Source File: BsScheduledJobCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setCrawler_Match(Boolean crawler, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("crawler", crawler);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #9
Source File: BsFavoriteLogCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setUrl_Fuzzy(String url, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regFuzzyQ("url", url);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #10
Source File: BsWebAuthenticationCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setPassword_Fuzzy(String password, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regFuzzyQ("password", password);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #11
Source File: BsWebAuthenticationCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setHostname_Match(String hostname, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("hostname", hostname);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #12
Source File: BsElevateWordCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setUpdatedBy_Match(String updatedBy, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("updatedBy", updatedBy);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #13
Source File: BsLabelTypeCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setCreatedBy_Match(String createdBy, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("createdBy", createdBy);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #14
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 4 votes vote down vote up
protected MatchQueryBuilder regMatchQ(String name, Object value) {
    checkEsInvalidQuery(name, value);
    MatchQueryBuilder matchQuery = QueryBuilders.matchQuery(name, value);
    regQ(matchQuery);
    return matchQuery;
}
 
Example #15
Source File: BsSearchLogCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setUserAgent_Match(String userAgent, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("userAgent", userAgent);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #16
Source File: BsSearchLogCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setUser_Fuzzy(String user, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regFuzzyQ("user", user);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #17
Source File: BsFileConfigCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setIntervalTime_Match(Integer intervalTime, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("intervalTime", intervalTime);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #18
Source File: BsDuplicateHostCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setUpdatedTime_Fuzzy(Long updatedTime, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regFuzzyQ("updatedTime", updatedTime);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #19
Source File: BsWebConfigCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setTimeToLive_Match(Integer timeToLive, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("timeToLive", timeToLive);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #20
Source File: BsSearchLogCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setSearchWord_Match(String searchWord, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("searchWord", searchWord);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #21
Source File: BsWebConfigCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setUpdatedTime_Fuzzy(Long updatedTime, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regFuzzyQ("updatedTime", updatedTime);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #22
Source File: BsFileConfigCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setIncludedPaths_Fuzzy(String includedPaths, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regFuzzyQ("includedPaths", includedPaths);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #23
Source File: BsWebConfigCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setUpdatedTime_Match(Long updatedTime, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("updatedTime", updatedTime);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #24
Source File: BsFileConfigCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setName_Match(String name, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("name", name);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #25
Source File: BsThumbnailQueueCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setTarget_Fuzzy(String target, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regFuzzyQ("target", target);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #26
Source File: BsScheduledJobCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setName_Match(String name, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("name", name);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #27
Source File: BsPathMappingCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setUpdatedBy_Match(String updatedBy, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("updatedBy", updatedBy);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #28
Source File: BsWebAuthenticationCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setUpdatedBy_Match(String updatedBy, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("updatedBy", updatedBy);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #29
Source File: BsFileAuthenticationCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setPassword_Match(String password, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("password", password);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}
 
Example #30
Source File: BsRelatedContentCQ.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setCreatedBy_Match(String createdBy, ConditionOptionCall<MatchQueryBuilder> opLambda) {
    MatchQueryBuilder builder = regMatchQ("createdBy", createdBy);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
}