首先,我对ES完全陌生。我在下面创建了ES搜索条件,用于搜索工作良好的项目,但我现在需要的是,我希望将make字段转换为不区分大小写的字段,以便搜索结果与hello、HeLlo、HELLO等相同。
我读过下面的文章,因为我的知识非常有限,所以我无法平静地应用于下面的例子:
将not_analyzed从make中删除没有帮助。
'indexes' => [
'my_project' => [
'client' => 'default',
'index_name' => 'hello',
'settings' => [
'index' => [
'analysis' => [
'analyzer' => [
'snowball_analyzer' => [
'type' => 'snowball',
'language' => 'English',
],
],
],
],
],
'types' => [
'item' => [
'mappings' => [
'uuid' => ['type' => 'string', 'index' => 'not_analyzed'],
'name' => ['type' => 'string', 'boost' => 8, 'analyzer' => 'snowball_analyzer'],
'make' => ['type' => 'string', 'index' => 'not_analyzed'],
]
],
],
],
],以下是我创建的查询:
1
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"term": {
"make": "HeLlo"
}
}
]
}
}
}
}
}发布于 2015-07-22 10:31:49
你必须添加“小写”过滤器。下面是我使用的类似配置的摘录:
settings:
index:
analysis:
analyzer:
custom_search_analyzer:
type: custom
tokenizer: standard
filter: [stopwords, asciifolding ,lowercase, snowball, elision, worddelimiter]在你的情况下,我想你应该这样改变:
...
'settings' => [
'index' => [
'analysis' => [
'analyzer' => [
'snowball_analyzer' => [
'type' => 'snowball',
'language' => 'English',
'filter' => [ 'lowercase' ]
],
],
],
],
],
...发布于 2015-07-22 14:47:11
这一次,我在我发布的第一个链接上打开了答案,它也解决了我的问题,所以我的案例不敏感的工作例子是:
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "HeLlo*"
}
}
]
}
}
}
}
}https://stackoverflow.com/questions/31560476
复制相似问题