栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

elasticsearch映射tokenizer关键字,以避免拆分令牌并启用通配符

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

elasticsearch映射tokenizer关键字,以避免拆分令牌并启用通配符

我找到了一个可行的解决方案:“关键字”令牌生成器。创建一个自定义分析器,并将其用于我要保留的字段的映射中,而不用空格分开:

    curl -XPUT 'localhost:9200/botanic/' -d '{ "settings":{     "index":{        "analysis":{"analyzer":{   "keylower":{      "tokenizer":"keyword",      "filter":"lowercase"   }}        }     }  },  "mappings":{        "specimens" : { "_all" : {"enabled" : true}, "_index" : {"enabled" : true}, "_id" : {"index": "not_analyzed", "store" : false}, "properties" : {     "_id" : {"type" : "string", "store" : "no","index": "not_analyzed"  } , ...     "LOCATIONID" : {"type" : "string",  "store" : "yes","index": "not_analyzed" } ,     "AVERAGEALTITUDEROUNDED" : {"type" : "string",  "store" : "yes","index": "analyzed" } ,     "CONTINENT" : {"type" : "string","analyzer":"keylower" } ,     "COUNTRYNAME" : {"type" : "string","analyzer":"keylower" } ,          "COUNTRYCODE" : {"type" : "string", "store" : "yes","index": "analyzed" } ,     "COUNTY" : {"type" : "string","analyzer":"keylower" } ,     "LOCALITY" : {"type" : "string","analyzer":"keylower" }       }        }    }}'

因此我可以在字段COUNTRYNAME的查询中使用通配符,该字段不会被拆分:

curl -XGET 'localhost:9200/botanic/specimens/_search?size=10' -d '{"fields"  : ["COUNTRYNAME"],     "query": {"query_string" : {         "query": "COUNTRYNAME:bol*"}},"aggs" : {    "general" : {        "terms" : { "field" : "COUNTRYNAME", "size":0        }    }}}'

结果 :

{    "took" : 14,    "timed_out" : false,    "_shards" : {        "total" : 5,        "successful" : 5,        "failed" : 0    },    "hits" : {        "total" : 45,        "max_score" : 1.0,        "hits" : [{     "_index" : "botanic",     "_type" : "specimens",     "_id" : "91E7B53B61DF4E76BF70C780315A5DFD",     "_score" : 1.0,     "fields" : {         "COUNTRYNAME" : ["Bolivia, Plurinational State of"]     } }, {     "_index" : "botanic",     "_type" : "specimens",     "_id" : "7D811B5D08FF4F17BA174A3D294B5986",     "_score" : 1.0,     "fields" : {         "COUNTRYNAME" : ["Bolivia, Plurinational State of"]     } } ...        ]    },    "aggregations" : {        "general" : { "buckets" : [{         "key" : "bolivia, plurinational state of",         "doc_count" : 45     } ]        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/394541.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号