我已经使用自定义分析器为停用词创建了索引。我希望弹性搜索在搜索时忽略这些单词。然后,我在elasticsearch映射中添加了一个文档数据。但是当我在kibana中通过查询查询“ the”关键字时。它不应显示任何成功的匹配,因为在my_analzer中,我在my_stop_word部分中放置了“ the”。但它显示了比赛。我研究过,如果您在映射字段建立索引时提到一个分析器。那么在查询时,它将默认使用该分析器。请帮助!
PUT /pandey
{
"settings":
{
"analysis":
{
"analyzer":
{
"my_analyzer":
{
"tokenizer": "standard",
"filter": [
"my_stemmer",
"english_stop",
"my_stop_word",
"lowercase"
]
}
},
"filter": {
"my_stemmer": {
"type": "stemmer",
"name": "english"
},
"english_stop":{
"type": "stop",
"stopwords": "_english_"
},
"my_stop_word": {
"type": "stop",
"stopwords": ["robot", "love", "affection", "play", "the"]
}
}
}
},
"mappings": {
"properties": {
"dialog": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
PUT pandey/_doc/1
{
"dailog" : "the boy is a robot. he is in love. i play cricket"
}
GET pandey/_search
{
"query": {
"match": {
"dailog": "the"
}
}
}
一个小的拼写错误可能会导致这种情况。
您为dialog
定义了映射,但是添加了字段名称为dailog
的文档。弹性的动态场映射行为将为其编制索引而不会出错。我们可以禁用它。
因此查询,"dailog": "the"
将使用默认分析器获得结果。