我想搜索字符串在字段中包含字符串。像在SQL中的搜索我试图使用正则搜索。
$params["query"]["bool"]["filter"][]["regexp"][$item_key] = '.*'.$search_pattern.'.*'
我只能搜索较低的单词。对于上词,它不起作用。示例:
我的标题是:ABC
如果搜索文本为:ABC->有结果
如果搜索文本为:ABC->无结果
我的映射配置是:
`'mappings' => [
'items' => [
"title" => [
"type" => "text",
"fields" => [
"keyword" => [
"type" => "keyword",
]
],
"fielddata" => true,
"index" => "not_analyzed",
]
]
]`
有人有任何想法在搜索方面不敏感吗?非常感谢。
您在布尔滤波器内使用前缀查询。Elasticsearch不要分析过滤器的查询。您可以将其正则态度移至查询上下文,其中查询项将由索引分析仪分析。为确保术语在索引和搜索弹性杂物时相同的术语在搜索时相同的分析仪。
您可以应用标准分析仪
{
"mappings": {
"items": {
"properties": {
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"fielddata": true,
"analyzer": "standard"
}
}
}
}
}
查询
{
"query": {
"regexp":{
"title": "ab.*"
}
}
}
希望这有帮助