在使用 NativeSearchQueryBuilder 的 Elasticsearch 中,如果与 multiMatchQuery 结合使用,范围查询过滤器将失败
In Elasticsearch while Using NativeSearchQueryBuilder the rangequery filter fails if combined with multiMatchQuery
你好,我正在尝试在 ElasticSearch 中查询,其中我想使用 multiMatchQuery 来搜索字符串并使用 rangequery 来过滤日期之间的数据来获取数据
Calendar compareDate = Calendar.getInstance();
compareDate.add(Calendar.DATE, 14);
SearchQuery query = new NativeSearchQueryBuilder().withIndices("project")
.withPageable(new PageRequest(offset, limit))
.withFilter(rangeQuery("startDate").from(new Date().getTime()).to(compareDate.getTime()))
.withFilter(multiMatchQuery(string,
new String[] { "name","platform", "department", "url"}).build();
日期过滤器查询失败,它为我提供了较早日期的数据。我尝试使用 using booleanQueryBuilder 仍然得到旧日期。
如果我使用没有 multiMatchQuery 的 rangeQuery 过滤器,它会给我正确的数据。但为什么这个组合不起作用?
使用 springdata 有什么解决办法吗?
我的文档将如下所示
{
"categories": [
{
"id": "ee625703-6103-6f94-b246-ff00003e0ef8",
"name": "Networking"
}
],
"id": "PROJECT_69ee95dcb88547e388491328bbb6fdcc",
"hostContentId": "69ee95dc-b885-47e3-8849-1328bbb6fdcc",
"orgName": "Parinati Solutions",
"title": "Parinati Solutions: Kansas City",
"summary": "Parinati Solutions this is a test project name...",
"categoryUrls": "networking",
"startDate": 1512572400000,
"endDate": 1512576000000,
"friendlyDates": "Dec 6 @ 9:00 am - 10:00 am",
"friendlyLocation": "Test local Foundation, Kansas City, MO",
"providerSearchId": "9b89acbc-2d03-4526-860c-2a71f891be4b",
"contentProvider": "sourcelink",
"contentType": "PROJECT",
"linkedinProfileUrl": null,
"allowMemberContact": null,
"firstName": null,
"lastName": null,
"expertise": null,
"twitterHandle": null,
"interests": null,
"tagLine": null,
"searchResultId": "9b89acbc-2d03-4526-860c-2a71f891be4b"
}
您需要使用 withQuery()
而不是 withFilter()
,它的命名很糟糕,本质上是 post_filter
。
您需要将两个查询合并到一个 bool 查询中:
withQuery(
boolQuery()
.must(multiMatchQuery(string, new String[] { "name","platform", "department", "url"}))
.filter(rangeQuery("startDate").from(new Date().getTime()).to(compareDate.getTime()))
)
你好,我正在尝试在 ElasticSearch 中查询,其中我想使用 multiMatchQuery 来搜索字符串并使用 rangequery 来过滤日期之间的数据来获取数据
Calendar compareDate = Calendar.getInstance();
compareDate.add(Calendar.DATE, 14);
SearchQuery query = new NativeSearchQueryBuilder().withIndices("project")
.withPageable(new PageRequest(offset, limit))
.withFilter(rangeQuery("startDate").from(new Date().getTime()).to(compareDate.getTime()))
.withFilter(multiMatchQuery(string,
new String[] { "name","platform", "department", "url"}).build();
日期过滤器查询失败,它为我提供了较早日期的数据。我尝试使用 using booleanQueryBuilder 仍然得到旧日期。 如果我使用没有 multiMatchQuery 的 rangeQuery 过滤器,它会给我正确的数据。但为什么这个组合不起作用? 使用 springdata 有什么解决办法吗?
我的文档将如下所示
{
"categories": [
{
"id": "ee625703-6103-6f94-b246-ff00003e0ef8",
"name": "Networking"
}
],
"id": "PROJECT_69ee95dcb88547e388491328bbb6fdcc",
"hostContentId": "69ee95dc-b885-47e3-8849-1328bbb6fdcc",
"orgName": "Parinati Solutions",
"title": "Parinati Solutions: Kansas City",
"summary": "Parinati Solutions this is a test project name...",
"categoryUrls": "networking",
"startDate": 1512572400000,
"endDate": 1512576000000,
"friendlyDates": "Dec 6 @ 9:00 am - 10:00 am",
"friendlyLocation": "Test local Foundation, Kansas City, MO",
"providerSearchId": "9b89acbc-2d03-4526-860c-2a71f891be4b",
"contentProvider": "sourcelink",
"contentType": "PROJECT",
"linkedinProfileUrl": null,
"allowMemberContact": null,
"firstName": null,
"lastName": null,
"expertise": null,
"twitterHandle": null,
"interests": null,
"tagLine": null,
"searchResultId": "9b89acbc-2d03-4526-860c-2a71f891be4b"
}
您需要使用 withQuery()
而不是 withFilter()
,它的命名很糟糕,本质上是 post_filter
。
您需要将两个查询合并到一个 bool 查询中:
withQuery(
boolQuery()
.must(multiMatchQuery(string, new String[] { "name","platform", "department", "url"}))
.filter(rangeQuery("startDate").from(new Date().getTime()).to(compareDate.getTime()))
)