我正在使用基于官方 ElasticSearch 客户端的mongoosastic 。Mongoosastic 是一个插件,它允许我将 ElasticSearch 与 MongoDB 一起使用。我已经完成了基本查询,例如
NodesModel.search({
"query_string": {
"query": "developed"
}
}, function(err, results) {
console.log(err, JSON.stringify(results));
});
他们工作正常。但是现在我正在尝试启用弹性搜索的词干提取功能。我使用了官方 ES 文档中的词干示例,但无法使其与 mongoosastic 一起使用。我试过了
NodesModel.search({
"query_string": {
"query": "developed"
},
"index": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"filter": ["standard", "lowercase", "my_stemmer"]
}
},
"filter": {
"my_stemmer": {
"type": "stemmer",
"name": "light_german"
}
}
}
}
}, function(err, results) {
console.log(err, JSON.stringify(results));
});
输出如下:
{ [Error: SearchPhaseExecutionException[Failed to execute phase [query], all sha
rds failed; shardFailures {[zn4Omh8tRy-ml0K0lRpMig][nodess][0]: SearchParseExcep
tion[[nodess][0]: query[_all:developed],from[-1],size[-1]: Parse Failure [Failed
to parse source [{"query":{"query_string":{"query":"developed"},"index":{"analy
sis":{"analyzer":{"my_analyzer":{"tokenizer":"standard","filter":["standard","lo
wercase","my_stemmer"]}},"filter":{"my_stemmer":{"type":"stemmer","name":"light_
german"}}}}}}]]]; nested: ElasticsearchParseException[Expected field name but go
t START_OBJECT "index"]; }{[zn4Omh8tRy-ml0K0lRpMig][nodess][1]: SearchParseExcep
tion[[nodess][1]: query[_all:developed],from[-1],size[-1]: Parse Failure [Failed
to parse source [{"query":{"query_string":{"query":"developed"},"index":{"analy
sis":{"analyzer":{"my_analyzer":{"tokenizer":"standard","filter":["standard","lo
wercase","my_stemmer"]}},"filter":{"my_stemmer":{"type":"stemmer","name":"light_
german"}}}}}}]]]; nested: ElasticsearchParseException[Expected field name but go
t START_OBJECT "index"]; }{[zn4Omh8tRy-ml0K0lRpMig][nodess][2]: SearchParseExcep
tion[[nodess][2]: query[_all:developed],from[-1],size[-1]: Parse Failure [Failed
to parse source [{"query":{"query_string":{"query":"developed"},"index":{"analy
sis":{"analyzer":{"my_analyzer":{"tokenizer":"standard","filter":["standard","lo
wercase","my_stemmer"]}},"filter":{"my_stemmer":{"type":"stemmer","name":"light_
german"}}}}}}]]]; nested: ElasticsearchParseException[Expected field name but go
t START_OBJECT "index"]; }{[zn4Omh8tRy-ml0K0lRpMig][nodess][3]: SearchParseExcep
tion[[nodess][3]: query[_all:developed],from[-1],size[-1]: Parse Failure [Failed
to parse source [{"query":{"query_string":{"query":"developed"},"index":{"analy
sis":{"analyzer":{"my_analyzer":{"tokenizer":"standard","filter":["standard","lo
wercase","my_stemmer"]}},"filter":{"my_stemmer":{"type":"stemmer","name":"light_
german"}}}}}}]]]; nested: ElasticsearchParseException[Expected field name but go
t START_OBJECT "index"]; }{[zn4Omh8tRy-ml0K0lRpMig][nodess][4]: SearchParseExcep
tion[[nodess][4]: query[_all:developed],from[-1],size[-1]: Parse Failure [Failed
to parse source [{"query":{"query_string":{"query":"developed"},"index":{"analy
sis":{"analyzer":{"my_analyzer":{"tokenizer":"standard","filter":["standard","lo
wercase","my_stemmer"]}},"filter":{"my_stemmer":{"type":"stemmer","name":"light_
german"}}}}}}]]]; nested: ElasticsearchParseException[Expected field name but go
t START_OBJECT "index"]; }]]
message: 'SearchPhaseExecutionException[Failed to execute phase [query], all s
hards failed; shardFailures {[zn4Omh8tRy-ml0K0lRpMig][nodess][0]: SearchParseExc
eption[[nodess][0]: query[_all:developed],from[-1],size[-1]: Parse Failure [Fail
ed to parse source [{"query":{"query_string":{"query":"developed"},"index":{"ana
lysis":{"analyzer":{"my_analyzer":{"tokenizer":"standard","filter":["standard","
lowercase","my_stemmer"]}},"filter":{"my_stemmer":{"type":"stemmer","name":"ligh
t_german"}}}}}}]]]; nested: ElasticsearchParseException[Expected field name but
got START_OBJECT "index"]; }{[zn4Omh8tRy-ml0K0lRpMig][nodess][1]: SearchParseExc
eption[[nodess][1]: query[_all:developed],from[-1],size[-1]: Parse Failure [Fail
ed to parse source [{"query":{"query_string":{"query":"developed"},"index":{"ana
lysis":{"analyzer":{"my_analyzer":{"tokenizer":"standard","filter":["standard","
lowercase","my_stemmer"]}},"filter":{"my_stemmer":{"type":"stemmer","name":"ligh
t_german"}}}}}}]]]; nested: ElasticsearchParseException[Expected field name but
got START_OBJECT "index"]; }{[zn4Omh8tRy-ml0K0lRpMig][nodess][2]: SearchParseExc
eption[[nodess][2]: query[_all:developed],from[-1],size[-1]: Parse Failure [Fail
ed to parse source [{"query":{"query_string":{"query":"developed"},"index":{"ana
lysis":{"analyzer":{"my_analyzer":{"tokenizer":"standard","filter":["standard","
lowercase","my_stemmer"]}},"filter":{"my_stemmer":{"type":"stemmer","name":"ligh
t_german"}}}}}}]]]; nested: ElasticsearchParseException[Expected field name but
got START_OBJECT "index"]; }{[zn4Omh8tRy-ml0K0lRpMig][nodess][3]: SearchParseExc
eption[[nodess][3]: query[_all:developed],from[-1],size[-1]: Parse Failure [Fail
ed to parse source [{"query":{"query_string":{"query":"developed"},"index":{"ana
lysis":{"analyzer":{"my_analyzer":{"tokenizer":"standard","filter":["standard","
lowercase","my_stemmer"]}},"filter":{"my_stemmer":{"type":"stemmer","name":"ligh
t_german"}}}}}}]]]; nested: ElasticsearchParseException[Expected field name but
got START_OBJECT "index"]; }{[zn4Omh8tRy-ml0K0lRpMig][nodess][4]: SearchParseExc
eption[[nodess][4]: query[_all:developed],from[-1],size[-1]: Parse Failure [Fail
ed to parse source [{"query":{"query_string":{"query":"developed"},"index":{"ana
lysis":{"analyzer":{"my_analyzer":{"tokenizer":"standard","filter":["standard","
lowercase","my_stemmer"]}},"filter":{"my_stemmer":{"type":"stemmer","name":"ligh
t_german"}}}}}}]]]; nested: ElasticsearchParseException[Expected field name but
got START_OBJECT "index"]; }]' } undefined
正如我看到的那样,mongoosastic 将第一个参数传递给 ES nodejs 客户端,如下所示:
schema.statics.search = function(query, options, cb){
if (arguments.length === 2) {
cb = arguments[1]
options = {}
}
options.hydrateOptions = options.hydrateOptions || defaultHydrateOptions || {};
if (query === null)
query = undefined
var model = this
, esQuery = {
body: {
query: query
},
index: options.index || indexName,
type: options.type || typeName
}
if (options.highlight) {
esQuery.body.highlight = options.highlight;
}
.......
所以我的问题是我怎样才能让词干工作?