我想在字段中搜索字符串包含字符串。像在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",
]
]
]`
在不区分大小写的情况下,是否有人对搜索有任何想法? 非常感谢你。
答案 0 :(得分:0)
您在bool过滤器中使用前缀查询。 Elasticsearch不会分析过滤器的查询。您可以将regex移动到查询上下文,索引分析器将分析查询字词。在索引和搜索弹性应用时,确保术语相同,同时搜索相同的分析器。
您可以应用standard分析器
{
"mappings": {
"items": {
"properties": {
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"fielddata": true,
"analyzer": "standard"
}
}
}
}
}
查询
{
"query": {
"regexp":{
"title": "ab.*"
}
}
}
希望这有帮助