9
인덱스 생성이라는 간단한 작업에 어려움을 겪고 있습니다. 목표는 분석기와 필드 매핑을 사용하여 인덱스를 만드는 것입니다. 분석기를 사용하여 색인을 생성 할 때 분석 API 호출을 통해 분석기와 대화 할 수 있지만 매핑 정보를 추가 할 때 색인 생성 호출이 "분석기 [analyzer1] [$ field] 필드에 없습니다"와 함께 실패합니다.매핑을 사용한 탄성 검색 인덱스 생성
#!/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