我正在尝试使用前缀再次搜索内容,如果我搜索二极管,我得到的结果与二极管不同。当二极管和二极管都返回相同的结果时,如何让ES返回结果?这是我在ES中使用的映射和设置。
"settings":{
"analysis": {
"analyzer": {
"lowercasespaceanalyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"articles": {
"properties": {
"title": {
"type": "text"
},
"url": {
"type": "keyword",
"index": "true"
},
"imageurl": {
"type": "keyword",
"index": "true"
},
"content": {
"type": "text",
"analyzer" : "lowercasespaceanalyzer",
"search_analyzer":"whitespace"
},
"description": {
"type": "text"
},
"relatedcontentwords": {
"type": "text"
},
"cmskeywords": {
"type": "text"
},
"partnumbers": {
"type": "keyword",
"index": "true"
},
"pubdate": {
"type": "date"
}
}
}
}
here is an example of the query I use
POST _search
{
"query": {
"bool" : {
"must" : {
"prefix" : { "content" : "capacitance" }
}
}
}
}发布于 2017-07-02 12:09:40
在您的索引中将不会有Diode一词。因此,如果你想得到相同的结果,你应该让你的查询上下文由相同的分析器来分析。
您可以像这样使用Query string query
"query_string" : {
"default_field" : "content",
"query" : "Diode",
"analyzer" : "lowercasespaceanalyzer"
}更新
您可以在查询之前分析上下文。
AnalyzeResponse resp = client.admin().indices()
.prepareAnalyze(index, text)
.setAnalyzer("lowercasespaceanalyzer")
.get();
String analyzedContext = resp.getTokens().get(0);
...然后使用analyzedContext作为新的查询上下文。
发布于 2017-07-04 01:45:19
这是因为您在搜索时和索引时使用了两个不同的分析器。因此,当您在搜索时输入查询"Diod“时,因为您使用了”空白“分析器,所以您的查询被解释为"Diod”。但是,因为您在索引时使用了"lowercasespaceanalyzer“,所以"diod”将被索引为"Diod“。只需在搜索和索引时使用相同的分析器,或者使用小写字符串的分析器,因为默认的“空白”分析器不会https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-whitespace-analyzer.html
https://stackoverflow.com/questions/44852735
复制相似问题