- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嗨,我正在尝试在 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/
试图找到范围查询的解决方案使用 QueryBuilders.rangeQuery 问题:DateFrom 可以为空或大于今天DateTill 可以为 null 或小于今天剩余数量可以为 null 或值
我正在使用 RangeQuery 获取数量在 0 到 2 之间的所有文档。当我执行查询时,Lucene 也会给我数量大于 2 的文档。我在这里缺少什么? 这是我的代码: Term lowerTerm
我已经实现了一个 Lucene.NET (2.9) 搜索具有允许我在一个月和一年内传递的查询参数的事件 - 然后返回该月内运行的所有事件(即,如果我在 2013 年 12 月通过它将匹配在 12 月的
基本上,我希望能够使用以下查询“短语查询”AND date:[20180101 TO 20181231]来查询索引。我尝试使用 MultiFieldQueryParser,但出现以下错误: 线程“ma
我正在使用高级 java rest 客户端 (6.5),我需要根据某个日期范围过滤数据 - 假设,我在同一个索引和 2 个文档中有这 4 个文档(添加了 postman 图像)'没有 publish_
嗨,我正在尝试在 ElasticSearch 中查询,其中我想使用 multiMatchQuery 来获取数据来搜索字符串,并使用 rangequery 来过滤日期之间的数据 Calendar com
我是一名优秀的程序员,十分优秀!