Reputation: 1322
I use spring 2.2.4.RELEASE
and spring-data-elasticsearch 3.2.4.RELEASE
My elastic version is 7.10
. I already have lot of index and data in it.
I just notice after once year that the search is not searching case insensitive.
MultiMatchQueryBuilder qb = QueryBuilders.multiMatchQuery(criteria)
.field("displayName")
.field("authorName")
.field("description")
.field("shortDescription")
.field("tag")
.field("translatedMetadataList")
.field("name")
.field("packageName")
.type(MultiMatchQueryBuilder.Type.PHRASE_PREFIX);
// we initialise the native search
NativeSearchQueryBuilder nativeSearch = new NativeSearchQueryBuilder()
.withQuery(qb)
.withPageable(PageRequest.of(page, size));
// if the category is set, we return only this category
if(categoryName.isPresent()) {
nativeSearch .withQuery(QueryBuilders.matchQuery(CATEGORY_NAME, categoryName.get()));
}
// convert native to search
SearchQuery searchQuery = nativeSearch.build();
Page<Game> gameList = gameRepo.search(searchQuery);
my index looks like this
"mappings" : {
"properties" : {
"category" : {
"type" : "nested",
"include_in_parent" : true,
"properties" : {
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"id" : {
"type" : "long"
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},...```
how could I do to search case insensitive ?
Thank you.
Upvotes: 0
Views: 38
Reputation: 442
Using a match query, we may only search by the full title, which is also case-sensitive.
I suggest you need something like search client text in multiple fields?
Then you have 2 options
private fun buildSoftSearchByIdentifiers(searchByIdentifiers: Set<String>) = QueryBuilders.boolQuery().apply {
searchByIdentifiers.forEach { identifier ->
val likeQuery = "*${identifier.toLowerCase()}*"
should(
QueryBuilders.wildcardQuery(Profile::firstName.name, likeQuery)
)
should(
QueryBuilders.wildcardQuery(Profile::lastName.name, likeQuery)
)
}
}
Upvotes: 0