我将我的问题改为完整的卷曲娱乐脚本.这样可以更容易地重现问题(使用自定义分析器搜索失败).我正在使用最新的ES版本
curl -XDELETE "http://localhost:9200/test_shingling"
Run Code Online (Sandbox Code Playgroud)
curl -XPOST "http://localhost:9200/test_shingling/" -d '{
"settings": {
"index": {
"number_of_shards": 10,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"ShingleAnalyzer": {
"tokenizer": "BreadcrumbPatternAnalyzer",
"filter": [
"standard",
"lowercase",
"filter_stemmer",
"filter_shingle"
]
}
},
"filter": {
"filter_shingle": {
"type": "shingle",
"max_shingle_size": 2,
"min_shingle_size": 2,
"output_unigrams": false
},
"filter_stemmer": {
"type": "porter_stem",
"language": "English"
}
},
"tokenizer": {
"BreadcrumbPatternAnalyzer": {
"type": "pattern",
"pattern": " |\\$\\$\\$"
}
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
curl -XPOST "http://localhost:9200/test_shingling/item/_mapping" -d '{
"item": {
"properties": {
"Title": {
"type": "string",
"search_analyzer": "ShingleAnalyzer",
"index_analyzer": "ShingleAnalyzer"
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
curl -XPOST "http://localhost:9200/test_shingling/item/" -d '{
"Title":"Kyocera Solar Panel Test"
}'
Run Code Online (Sandbox Code Playgroud)
curl 'localhost:9200/test_shingling/_analyze?pretty=1&analyzer=ShingleAnalyzer' -d 'Kyocera Solar Panel Test'
Run Code Online (Sandbox Code Playgroud)
curl -XPOST "http://localhost:9200/test_shingling/_refresh"
Run Code Online (Sandbox Code Playgroud)
curl -XPOST "http://localhost:9200/test_shingling/item/_search?pretty=true" -d '{
"query": {
"term": {
"Title": "Kyocera Solar Panel Test"
}
}
}'
Run Code Online (Sandbox Code Playgroud)
curl -XPOST "http://localhost:9200/test_shingling/item/_search?pretty=true" -d '{
"query": {
"term": {
"Title": "Kyocera Solar Panel Test"
}
}
}'
Run Code Online (Sandbox Code Playgroud)
curl -XPOST "http://localhost:9200/test_shingling/item/_search?pretty=true" -d '{
"query": {
"query_string": {
"default_field": "Title",
"query": "Kyocera Solar Panel Test"
}
}
}'
Run Code Online (Sandbox Code Playgroud)
curl -XPOST "http://localhost:9200/test_shingling/item/_search?pretty=true" -d '{
"query": {
"query_string": {
"default_field": "Title",
"query": "solar panel"
}
}
}'
Run Code Online (Sandbox Code Playgroud)
术语查询将搜索完全匹配,并且不会将ShingleAnalyzer应用于您的查询.
因此,您必须使用匹配查询,这将在搜索时将Analyzer应用于您的查询字符串.
全字搜索
curl -XPOST "http://localhost:9200/test_shingling/item/_search" -d'{
"query": {
"match": {
"Title": "Kyocera Solar Panel Test"
}
}
}'
Run Code Online (Sandbox Code Playgroud)
部分单词搜索
curl -XPOST "http://localhost:9200/test_shingling/item/_search" -d'{
"query": {
"match": {
"Title": "Panel Test"
}
}
}'
Run Code Online (Sandbox Code Playgroud)
另一个部分词搜索
curl -XPOST "http://localhost:9200/test_shingling/item/_search" -d'{
"query": {
"match": {
"Title": "Solar Panel Test"
}
}
}'
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你..!
| 归档时间: |
|
| 查看次数: |
5141 次 |
| 最近记录: |