有个人长的像洋葱,走着走着就哭了…….

场景,我想实现大小写区分查询,但是es默认都会将字段的内容转换为小写。 想自定义标记过滤器,但是这个lowercase 是boolean型的么?怎么定义,实现大小写区分查询

Elasticsearch | 作者 artomu | 发布于2016年11月11日 | 阅读数:10207

这是我的mapping设置:
"template_srclog": {
      "order": 0,
      "template": "srclog*",
      "settings": {
         "index": {
            "refresh_interval": "5s",
            "store": {
               "type": "niofs"
            },
            "analysis": {
               "analyzer": {
                  "default": {
                     "type": "ik"
                  }
               }
            },
            "number_of_shards": "6",
            "number_of_replicas": "0"
         }
      },
      "mappings": {
         "srclog_type": {
            "_ttl": {
               "default": "7d",
               "enabled": false
            },
            "_source": {
               "enabled": true
            },
            "dynamic_templates": [
               {
                  "millis-to-long": {
                     "mapping": {
                        "index": "not_analyzed",
                        "type": "long"
                     },
                     "match_mapping_type": "string",
                     "match": "*Millis"
                  }
               },
               {
                  "lineNumber-to-long": {
                     "mapping": {
                        "index": "not_analyzed",
                        "type": "long"
                     },
                     "match_mapping_type": "string",
                     "match": "lineNumber"
                  }
               },
               {
                  "sting-to-long": {
                     "mapping": {
                        "index": "not_analyzed",
                        "type": "long"
                     },
                     "match_mapping_type": "string",
                     "match": "*_long"
                  }
               },
               {
                  "sting-to-double": {
                     "mapping": {
                        "index": "not_analyzed",
                        "type": "double"
                     },
                     "match_mapping_type": "string",
                     "match": "*_double"
                  }
               },
               {
                  "sting-to-boolean": {
                     "mapping": {
                        "index": "not_analyzed",
                        "type": "boolean"
                     },
                     "match_mapping_type": "string",
                     "match": "*_boolean"
                  }
               },
               {
                  "lineContent": {
                     "mapping": {
                        "index": "not_analyzed",
                        "type": "string"
                     },
                     "match": "*lineContent"
                  }
               },
               {
                  "default-fields": {
                     "mapping": {
                        "index": "not_analyzed",
                        "type": "string"
                     },
                     "match_mapping_type": "string"
                  }
               }
            ],
            "_all": {
               "enabled": true
            }
         }
      },
      "aliases": {}
   }
}
已邀请:

artomu - 90后IT男

赞同来自:

看了一个上午的官网api:有个标记过滤器,Token Filters,里面有Lowercase Token Filter、Uppercase Token Filter。然后尝试一把设置在下面,发觉还是不行,大小写还是不区分。然后看见了一个分析器:Keyword Tokenizer,这个可以。可这就坑爹了,这个做不了分词,也就是你的字段是什么内容,你就要完全输入什么内容精确检索,否则查不到。 有没有人尝试过?怎么去实现大小写区分查询呢
 
PUT /mytest
{
    "settings": {
        "analysis": {
            "analyzer": {
                "my_analyzer": {
                    "type":         "custom",
                    "tokenizer":    "ik",
                    "filter":  "uppercase"
            }}
}
    }}
PUT /mytest/_mapping/my_type
{
    "properties": {
        "capital": {
            "type":      "string",
            "analyzer":  "my_analyzer"
        }
    }
}
 

CODER_LIU - 90后coder

赞同来自:

我现在也遇到这个问题了,最后怎么解决的呢?

要回复问题请先登录注册