Search string in elastic search DB. Can any one please help to resolve this issue.
I am facing issue when I try using below snippet,
BoolQueryBuilder qb = QueryBuilders.boolQuery();
QueryBuilder qbm = QueryBuilders.matchQuery("Coloumname", "textValue");
Thanks.
Related
I am creating a simple elastic request with Nest.
var searchRequest = new SearchRequest()
{
Aggregations = new AggregationDictionary()
{
}
};
When I serialize the query with elasticClient.RequestResponseSerializer.SerializeToString(searchRequest the query I am seeing like this :
{"aggs":{},"aggregations":{}}
Aggregation sections were created two times.
What should I do?
Is this a problem?
My nest version and elastic Search version are 7.6.2
Thanks.
I have two different documents in the Elasticsearch - Decision and Nomination.
Right now I can only search all of the documents wit Decision type.
I use Spring Data Elasticsearch for this purpose:
PageRequest pageRequest = DecisionUtils.createPageRequest(pageNumber, pageSize);
MultiMatchQueryBuilder fuzzyMmQueryBuilder = multiMatchQuery(query, "name", "description").fuzziness("AUTO");
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder().should(fuzzyMmQueryBuilder);
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
nativeSearchQueryBuilder.withIndices(ESDecision.INDEX_NAME).withTypes(ESDecision.TYPE).withPageable(pageRequest);
NativeSearchQuery nativeSearchQuery = nativeSearchQueryBuilder.withQuery(boolQueryBuilder).withPageable(pageRequest).build();
return elasticsearchTemplate.queryForPage(nativeSearchQuery, ESDecision.class);
Is it possible to update this code to search by Decision and Nomination simultaneously in order to get the search result from both of them ? If the answer is yes - please show an example how to implement this and also please show how to determine at search results who is Decision and who is Nomination ? Is there any classification field that can be added into search result entity for this purpose ?
I want to create a query with Elasticsearch Java API but I don't know how to create an OR clause? What I want to query is;
SELECT *
FROM USERS
WHERE (user.name = "admin") AND (user.message LIKE "test*") AND (user.age = "30" OR user.status = "major")
I have created a query like below but I don't know how to create an OR clause like sql query;
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.matchQuery("name", "admin"));
boolQueryBuilder.must(QueryBuilders.matchQuery("message", "test*"));
boolQueryBuilder.must(QueryBuilders.matchQuery("age", "30"));
boolQueryBuilder.must(QueryBuilders.matchQuery("status","major"));
You simply need to capture the OR condition inside another bool/should query
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.matchQuery("name", "admin"));
boolQueryBuilder.mustNot(QueryBuilders.matchQuery("message", "test*"));
BoolQueryBuilder orQuery = QueryBuilders.boolQuery();
orQuery.should(QueryBuilders.matchQuery("age", "30"));
orQuery.should(QueryBuilders.matchQuery("status","major"));
orQuery.minimumNumberShouldMatch(1);
boolQueryBuilder.must(orQuery);
PS: not sure why you have a mustNot for your second constraint.
The "should" keyword in bool queries works like "OR", but in Elasticsearch those queries are not very sharp as everything is scored.
Have a look at:
https://www.elastic.co/guide/en/elasticsearch/guide/current/bool-query.html#bool-query
Also there are very good examples in the book Elasticsearch in Action.
I hav ethis piece of code now as of elastic search 2.4 QueryFilterBuilder is deprecated and its showing error.
QueryFilterBuilder queryFilterBuilder = FilterBuilders.queryFilter(esQueryBuilder); i tried to replace it with QueryBuider but its not accepting.
if (StringUtils.isNotBlank(textQuery)) {
QueryBuilder esQueryBuilder = CatalogKeywordSearchHelper.getAppropriateESQueryForUserQuery(storeId, textQuery);
QueryFilterBuilder queryFilterBuilder = FilterBuilders.queryFilter(esQueryBuilder);
filterBuildersMap.put(IdxSchemaConstants.TEXT_QUERY, queryFilterBuilder);
}
Query filters have been deprecated in ES 2.0 and since then queries can now be used in a filter context, you can simply use a bool/filter query and put your query in it:
if (StringUtils.isNotBlank(textQuery)) {
QueryBuilder esQueryBuilder = CatalogKeywordSearchHelper.getAppropriateESQueryForUserQuery(storeId, textQuery);
# change this line
BoolQueryBuilder queryFilterBuilder = QueryBuilders.boolQuery()
.filter(esQueryBuilder);
filterBuildersMap.put(IdxSchemaConstants.TEXT_QUERY, queryFilterBuilder);
}
Alternative for this as i am not getting for gte() as i am migrating elastic search from 1.4 to 2.4?
Double price;
NotFilterBuilder excMaxPriceFilter = FilterBuilders.notFilter(FilterBuilders.rangeFilter("exclude_max_price").gte(price));
You can rewrite your code to this:
BoolQueryBuilder excMaxPriceFilter = QueryBuilders.boolQuery()
.mustNot(QueryBuilders.rangeQuery("exclude_max_price").gte(price));