[英]Elasticsearch index creation with mapping
I'm struggling with the simple task of index creation, the goal is to create an index with an analyzer and a field mapping. 我正在努力完成索引创建的简单任务,目标是使用分析器和字段映射创建索引。 When I create a index with an analyzer i can talk to the analyzer via the analyze api calls, but when I add the mapping information the create index calls fails with "Analyzer [analyzer1] not found for field [$field]]", I created a script to show the problem:
当我使用分析器创建索引时,我可以通过analyze api调用与分析器通信,但是当我添加映射信息时,创建索引调用失败,并且“找不到字段[$ field]]的Analyzer [analyzer1]]”,I创建了一个脚本来显示问题:
#!/bin/bash
INDEX_NAME="test1"
echo "delete index just to be sure"
curl -XDELETE "http://localhost:9200/$INDEX_NAME/"; echo
echo "create new index"
curl -X PUT "http://localhost:9200/$INDEX_NAME/" -d '{
"index":{
"analysis":{
"analyzer":{
"analyzer1":{
"type":"custom",
"tokenizer":"standard",
"filter":[ "standard", "lowercase", "stop", "kstem", "ngram" ]
}
},
"filter":{
"ngram":{
"type":"ngram",
"min_gram":2,
"max_gram":15
}
}
}
}
}'; echo
echo "analyze something with our shiny new analyzer"
curl -XGET "localhost:9200/$INDEX_NAME/_analyze?analyzer=analyzer1&pretty=true" -d 'abcd'
echo "remove the created index"
curl -XDELETE "http://localhost:9200/$INDEX_NAME/"; echo
echo "create new index again with mapping"
curl -X PUT "http://localhost:9200/$INDEX_NAME/" -d '{
"index":{
"analysis":{
"analyzer":{
"analyzer1":{
"type":"custom",
"tokenizer":"standard",
"filter":[ "standard", "lowercase", "stop", "kstem", "ngram" ]
}
},
"filter":{
"ngram":{
"type":"ngram",
"min_gram":2,
"max_gram":15
}
}
}
},
"mappings": {
"product": {
"properties": {
"title": {
"type": "string",
"search_analyzer" : "analyzer1",
"index_analyzer" : "analyzer1"
}
}
}
}
}'; echo
I believe your issue is that the analysis
settings need to be nested within a settings
node in your JSON, not within an index
node as you have it. 我相信您的问题是
analysis
设置需要嵌套在JSON中的settings
节点中,而不是嵌套在index
节点中。 Please reference the Elasticsearch Create Index API for details on constructing the JSON. 有关构造JSON的详细信息,请参阅Elasticsearch Create Index API 。
Therefore, your create index call should look like the the following: 因此,您的创建索引调用应如下所示:
curl -X PUT "http://localhost:9200/$INDEX_NAME/" -d '{
"settings":{
"analysis":{
"analyzer":{
"analyzer1":{
"type":"custom",
"tokenizer":"standard",
"filter":[ "standard", "lowercase", "stop", "kstem", "ngram" ]
}
},
"filter":{
"ngram":{
"type":"ngram",
"min_gram":2,
"max_gram":15
}
}
}
},
"mappings": {
"product": {
"properties": {
"title": {
"type": "string",
"search_analyzer" : "analyzer1",
"index_analyzer" : "analyzer1"
}
}
}
}
}';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.