gpt4 book ai didi

java - 为什么elasticsearch matchQuery不返回结果?

转载 作者:行者123 更新时间:2023-12-02 09:21:01 24 4
gpt4 key购买 nike

我已成功使用elasticsearch对内容建立了索引,但在尝试查询内容时遇到了麻烦。

我想要做的是搜索包含值“ipsum”(任何术语)AND术语的所有文档 “type”应等于“cq:Page”。

我正在使用高级 Rest Java 客户端。尝试使用过滤和 Boolquery,但它返回零结果。

示例:

SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.from(0);
sourceBuilder.size(10);

SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("gettingstarted");
searchRequest.source(sourceBuilder);

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.queryStringQuery("ipsum"));
boolQueryBuilder.must(QueryBuilders.matchQuery("type", "cq:Page"));
sourceBuilder.query(boolQueryBuilder);


SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

数据如下所示:

{ 
"took":4,
"timed_out":false,
"_shards":{
"total":1,
"successful":1,
"skipped":0,
"failed":0
},
"hits":{
"total":{
"value":1,
"relation":"eq"
},
"max_score":1.0,
"hits":[
{
"_index":"gettingstarted",
"_type":"_doc",
"_id":"2",
"_score":1.0,
"_source":{
"docs":[
{
"id":"/content/we-retail/us/en/community/members",
"type":"cq:Page",
"jcr_title":"Members",
"jcr:created":"java.util.GregorianCalendar[time=1564730906165,areFieldsSet=true,areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id=\"GMT+02:00\",offset=7200000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2019,MONTH=7,WEEK_OF_YEAR=31,WEEK_OF_MONTH=1,DAY_OF_MONTH=2,DAY_OF_YEAR=214,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=9,HOUR_OF_DAY=9,MINUTE=28,SECOND=26,MILLISECOND=165,ZONE_OFFSET=7200000,DST_OFFSET=0]",
"cq:lastModified":"java.util.GregorianCalendar[time=1518654268630,areFieldsSet=true,areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id=\"GMT-05:00\",offset=-18000000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2018,MONTH=1,WEEK_OF_YEAR=7,WEEK_OF_MONTH=3,DAY_OF_MONTH=14,DAY_OF_YEAR=45,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=7,HOUR_OF_DAY=19,MINUTE=24,SECOND=28,MILLISECOND=630,ZONE_OFFSET=-18000000,DST_OFFSET=0]",
"manualCreationDate":"2019-09-05T13:21:00.000+02:00",
"jcr:primaryType":"cq:PageContent",
"sling:resourceType":"social/console/components/basepage",
"searchDescription":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sportsman delighted improving dashwoods gay instantly happiness six. Ham now amounted absolute not mistaken way pleasant whatever. At an these still no dried folly stood thing. Rapid it on hours hills it seven years. If polite he active county in spirit an. Mrs ham intention promotion engrossed assurance defective. Confined so graceful building opinions whatever trifling in. Insisted out differed ham man endeavor expenses. At on he total their he songs. Related compact effects is on settled do.",
"pageImportanceRank":"4"
}, ...

也尝试过此操作,但没有成功,它返回零结果。

boolQueryBuilder.must(QueryBuilders.matchQuery("type", NT_PAGE));

最佳答案

也许是这样的:

GET index/_search
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "ipsum",
"fields": []
}
},
{
"match": {
"type": "cq:Page"
}
}
]
}
}
}

"fields": [] -> meaning all fields

关于java - 为什么elasticsearch matchQuery不返回结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58694258/

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