Elasticsearch 5 - text/keyword 字段中不区分大小写的精确匹配
Elasticsearch 5 - case insensitive exact matching in a text/keyword field
我在ES中的文档中有一个entity_name
字段,是一个text/keyword字段,其映射如下:
{
"my_index": {
"mappings": {
"my_type": {
"properties": {
"entity_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
我想要实现的是构建一个查询以获取在其 entity_name
字段中包含 'ABC' 的文档(如 'ABC Company'、'company abc'),但应该排除那些 'ABC' 不区分大小写的(例如 'ABC'、'abc'、'Abc')。
我试过这样的查询:
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"entity_name": "ABC"
}
}
],
"must_not": [
{
"term": {
"entity_name.keyword": "ABC"
}
}
]
}
}
}
但是没有处理不区分大小写的问题
如有任何帮助,我们将不胜感激。提前致谢:)
尝试向其中添加分词器以帮助过滤您的搜索
{
"my_index": {
"settings": {
"analysis": {
"analyzer": {
"case_insensitive": {
"tokenizer": "keyword",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"my_type": {
"properties": {
"entity_name": {
"type": "text",
"analyzer": "case_insensitive",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/5.4/analysis-tokenizers.html
我在ES中的文档中有一个entity_name
字段,是一个text/keyword字段,其映射如下:
{
"my_index": {
"mappings": {
"my_type": {
"properties": {
"entity_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
我想要实现的是构建一个查询以获取在其 entity_name
字段中包含 'ABC' 的文档(如 'ABC Company'、'company abc'),但应该排除那些 'ABC' 不区分大小写的(例如 'ABC'、'abc'、'Abc')。
我试过这样的查询:
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"entity_name": "ABC"
}
}
],
"must_not": [
{
"term": {
"entity_name.keyword": "ABC"
}
}
]
}
}
}
但是没有处理不区分大小写的问题
如有任何帮助,我们将不胜感激。提前致谢:)
尝试向其中添加分词器以帮助过滤您的搜索
{
"my_index": {
"settings": {
"analysis": {
"analyzer": {
"case_insensitive": {
"tokenizer": "keyword",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"my_type": {
"properties": {
"entity_name": {
"type": "text",
"analyzer": "case_insensitive",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/5.4/analysis-tokenizers.html