gpt4 book ai didi

java - 在 Elasticsearch 中使用 NativeSearchQueryBuilder 时,如果与 multiMatchQuery 结合使用,rangequery 过滤器会失败

转载 作者:行者123 更新时间:2023-11-30 06:22:47 30 4
gpt4 key购买 nike

嗨,我正在尝试在 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();

日期过滤器查询失败,它为我提供了较旧日期的数据。我尝试使用 booleanQueryBuilder 仍然得到旧日期。如果我使用 rangeQuery 过滤器而不使用 multiMatchQuery,它会给我正确的数据。但为什么这个组合不起作用呢?使用 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

您需要将两个查询合并到一个 boolean 查询中:

withQuery(
boolQuery()
.must(multiMatchQuery(string, new String[] { "name","platform", "department", "url"}))
.filter(rangeQuery("startDate").from(new Date().getTime()).to(compareDate.getTime()))
)

关于java - 在 Elasticsearch 中使用 NativeSearchQueryBuilder 时,如果与 multiMatchQuery 结合使用,rangequery 过滤器会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47774183/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com