spring - 春季数据弹性搜索无法在字段上正确搜索
问题描述
我想搜索我的索引的三个字段:标题、作者名和描述;
我的搜索看起来像:
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.multiMatchQuery(criteria)
.field("title")
.field("authorName")
.field("description")
.type(MultiMatchQueryBuilder.Type.BEST_FIELDS))
.withPageable(PageRequest.of(page, size))
.build();
Page<Ebook> ebookList = ebookRepo.search(searchQuery);
我已将这些文档编入索引:
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 5,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "ebook",
"_type" : "ebook",
"_id" : "9",
"_score" : 1.0,
"_source" : {
"id" : 9,
"size" : null,
"numberOfPages" : 10,
"companyId" : 656,
"price" : 10.0,
"title" : "Welcome to my life",
"authorName" : "JB2",
"description" : "Welcome to my life 3",
"language" : "FR",
"ebookPath" : null,
"ebookDownloadUrl" : null,
"rating" : {
"ratingId" : 10,
"average" : 5.0,
"starsByUserId" : {
"131" : 5
},
"stars" : {
"5" : 1
}
},
"coverPath" : null,
"coverDownloadUrl" : null,
"iconPath" : null,
"iconDownloadUrl" : null,
"category" : {
"id" : 1,
"name" : "Webtoon",
"subCategoryList" : [ ]
},
"subCategory" : {
"id" : 2,
"name" : "Adventure"
},
"repositoryGeneratedId" : "1588336718863",
"userReview" : [
{
"id" : 11,
"comment" : "I dont like it. I give 5 stars",
"commentDate" : 1588336718989,
"appUserId" : 131,
"stars" : 5
}
],
"status" : "INITIATED"
}
},
{
"_index" : "ebook",
"_type" : "ebook",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"id" : 5,
"size" : null,
"numberOfPages" : 10,
"companyId" : 2,
"price" : 10,
"title" : "Welcome to my life",
"authorName" : "kosted 3",
"description" : "Ceci est une autre description 3",
"language" : "FR",
"ebookPath" : null,
"ebookDownloadUrl" : null,
"rating" : {
"ratingId" : 6,
"average" : 0.0,
"starsByUserId" : { },
"stars" : { }
},
"coverPath" : null,
"coverDownloadUrl" : null,
"iconPath" : null,
"iconDownloadUrl" : null,
"category" : {
"id" : 1,
"name" : "Webtoon"
},
"subCategory" : {
"id" : 2,
"name" : "Adventure"
},
"repositoryGeneratedId" : "1588372761403",
"userReview" : [ ],
"status" : "INITIATED"
}
},
{
"_index" : "ebook",
"_type" : "ebook",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"id" : 3,
"size" : null,
"numberOfPages" : 10,
"companyId" : 2,
"price" : 10,
"title" : "Welcome to my life",
"authorName" : "kosted 2",
"description" : "Ceci est une autre description 2",
"language" : "FR",
"ebookPath" : null,
"ebookDownloadUrl" : null,
"rating" : {
"ratingId" : 4,
"average" : 0.0,
"starsByUserId" : { },
"stars" : { }
},
"coverPath" : null,
"coverDownloadUrl" : null,
"iconPath" : null,
"iconDownloadUrl" : null,
"category" : {
"id" : 1,
"name" : "Webtoon"
},
"subCategory" : {
"id" : 2,
"name" : "Adventure"
},
"repositoryGeneratedId" : "1588372758036",
"userReview" : [ ],
"status" : "INITIATED"
}
},
{
"_index" : "ebook",
"_type" : "ebook",
"_id" : "6",
"_score" : 1.0,
"_source" : {
"id" : 6,
"size" : null,
"numberOfPages" : 10,
"companyId" : 655,
"price" : 10,
"title" : "Welcome to my life",
"authorName" : "JBB",
"description" : "Welcome to my life 2",
"language" : "FR",
"ebookPath" : null,
"ebookDownloadUrl" : null,
"rating" : {
"ratingId" : 7,
"average" : 0.0,
"starsByUserId" : { },
"stars" : { }
},
"coverPath" : null,
"coverDownloadUrl" : null,
"iconPath" : null,
"iconDownloadUrl" : null,
"category" : {
"id" : 1,
"name" : "Webtoon",
"subCategoryList" : [ ]
},
"subCategory" : {
"id" : 2,
"name" : "Adventure"
},
"repositoryGeneratedId" : "1588336718576",
"userReview" : [ ],
"status" : "INITIATED"
}
},
{
"_index" : "ebook",
"_type" : "ebook",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"id" : 1,
"size" : null,
"numberOfPages" : 10,
"companyId" : 2,
"price" : 10,
"title" : "Welcome to my life",
"authorName" : "kosted",
"description" : "Book about my life",
"language" : "FR",
"ebookPath" : null,
"ebookDownloadUrl" : null,
"rating" : {
"ratingId" : 2,
"average" : 0.0,
"starsByUserId" : { },
"stars" : { }
},
"coverPath" : null,
"coverDownloadUrl" : null,
"iconPath" : null,
"iconDownloadUrl" : null,
"category" : {
"id" : 1,
"name" : "Webtoon"
},
"subCategory" : {
"id" : 2,
"name" : "Adventure"
},
"repositoryGeneratedId" : "1588372748126",
"userReview" : [ ],
"status" : "INITIATED"
}
}
]
}
}
当我使用“JB”或“jb”甚至“JB2”进行搜索时,当有作者名称为 JB2 的电子书时,我的结果为 0。
我使用弹簧 2.2.4.RELEASE 和弹簧数据弹性搜索 3.2.4.RELEASE。我的代码做错了什么?关于如何纠正它的任何想法?提前致谢
解决方案
推荐阅读
- wordpress - 重力形成条件
- reactjs - 带有反应的 FIrebase 登录
- mongodb - Mongodb在集合中找到前10个最大的数组项
- javascript - TypeError: Object(...) is not a function React.js
- java - 我正在尝试合并两个排序的数组,但得到 java.lang.ArrayIndexOutOfBoundsException: 5 无法弄清楚为什么
- javascript - 数组过滤器和如果是真实的地图数据
- javascript - Javascript将图像转换为文件返回零
- mysql - SQLyog 函数:从 INNER JOIN 返回值时出现语法错误
- javascript - 函数中意外未定义
- memory-management - 这里的每个 24 位页表条目如何?