Elasticsearch-Python 2.7-为analyzer配置索引
Elasticsearch-Python 2.7-Configure an index for analyzer
我正在尝试使用 python API 和以下代码构建索引(特别是我正在尝试配置分析器):
doc = {
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [ "lowercase", "asciifolding" ]
}
}
}
}
}
res = es.indices.create(index='index_db',body=doc)
但是当我尝试向数据库提供一些示例数据时:'My œsophagus caused a débâcle'(网站的相同示例)我没有获得:'my, oesophagus, caused, a, debacle' 但又是:'my, œsophagus caused, a, débâcle' .我认为问题出在索引的创建上。我使用的语法正确吗?
经过多次尝试,我找到了解决方案。这是一个语法问题。
正确答案是:
doc = {
"index" : {
"analysis" : {
"analyzer" : {
"default" : {
"tokenizer" : "standard",
"filter" : ["standard", "asciifolding"]
}
}
}
}
}
es.indices.create(index='forensic_db',body=doc)
我正在尝试使用 python API 和以下代码构建索引(特别是我正在尝试配置分析器):
doc = {
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [ "lowercase", "asciifolding" ]
}
}
}
}
}
res = es.indices.create(index='index_db',body=doc)
但是当我尝试向数据库提供一些示例数据时:'My œsophagus caused a débâcle'(网站的相同示例)我没有获得:'my, oesophagus, caused, a, debacle' 但又是:'my, œsophagus caused, a, débâcle' .我认为问题出在索引的创建上。我使用的语法正确吗?
经过多次尝试,我找到了解决方案。这是一个语法问题。 正确答案是:
doc = {
"index" : {
"analysis" : {
"analyzer" : {
"default" : {
"tokenizer" : "standard",
"filter" : ["standard", "asciifolding"]
}
}
}
}
}
es.indices.create(index='forensic_db',body=doc)