【发布时间】:2016-07-19 15:07:09
【问题描述】:
我已经成功地为 elasticsearch 实现了词干提取,因此当我搜索“代码”时,我会遇到“代码”和“编码”等。
当我尝试在查询中使用“must_not”字段时,出现了我的问题。当我在“must_not”字段中包含“code”时,这很好,我仍然可以按预期得到结果,但是当我搜索“codes”时,即使有包含单词“codes”的文档,我也没有得到任何结果" 肯定在其中。
我的查询如下:
for(i = 0; i < exclude_words.length; i++)
{
must_not.push({term:{text:exclude_words[i].toLowerCase()}});
}
query = {
"filtered": {
"query": {
"dis_max": {
"queries": [
{"match": {"text": term}},
{"match": {"title": term}}
]
}
},
"filter": {
"bool": {
"must_not": must_not
}
}
}
}
我正在使用 node.js 的 elasticsearch api 来构建我的查询并从 elasticsearch 获取结果。
我假设我遇到了这个问题是因为词干提取,并且“代码”在搜索索引中存储为“代码”。
有没有办法在不使用外部算法来阻止我的查询的情况下解决这个问题?或者有什么优雅的方法可以解决这个问题?
非常感谢任何帮助!
更新
这是我的分析仪:
{
"settings": {
"analysis": {
"analyzer": {
"stopword_analyzer": {
"type": "snowball",
"stopwords": ["a", "able", "about", "across", "after", "all", "almost", "also", "am", "among", "an", "and", "any", "are", "as", "at", "be", "because", "been", "but", "by", "can", "cannot", "could", "dear", "did", "do", "does", "either", "else", "ever","every", "for", "from", "get", "got", "had", "has", "have", "he", "her", "hers", "him", "his", "how", "however", "i", "if", "in", "into", "is", "it", "its", "just", "least", "let", "like", "may", "me", "might", "most", "must", "my", "neither", "no", "nor", "not", "of", "off", "often", "on", "only", "or", "other", "our", "own", "rather", "said", "say", "says", "she", "should", "since", "so", "some", "than", "that", "the", "their", "them", "then", "there", "these", "they", "this", "tis", "to", "too", "us", "wants", "was", "we", "were", "what", "when", "where", "which", "while", "who", "whom", "why", "will", "with", "would", "yet", "you", "your"]
}
}
}
}
文本字段具有以下映射:
"text": {
"type": "string",
"analyzer": "stopword_analyzer"
}
【问题讨论】:
-
text字段的映射是什么? -
用它更新了问题,谢谢!
标签: javascript node.js elasticsearch