我需要一个建议来提高我的搜索性能。现在写,我正在用 node.js 和 couchbase 开发一个后端服务。我的索引定义如下:
{"name": "product_search",
"type": "fulltext-index",
"params": {
"doc_config": {
"docid_prefix_delim": "",
"docid_regexp": "",
"mode": "type_field",
"type_field": "_type"
},
"mapping": {
"default_analyzer": "standard",
"default_datetime_parser": "dateTimeOptional",
"default_field": "_all",
"default_mapping": {
"default_analyzer": "",
"dynamic": true,
"enabled": false
},
"default_type": "_default",
"docvalues_dynamic": true,
"index_dynamic": true,
"store_dynamic": false,
"type_field": "_type",
"types": {
"Product": {
"default_analyzer": "",
"dynamic": false,
"enabled": true,
"properties": {
"categories": {
"default_analyzer": "",
"dynamic": true,
"enabled": true,
"properties": {
"\"$ref\"": {
"enabled": true,
"dynamic": false,
"fields": [
{
"analyzer": "keyword",
"index": true,
"name": "\"$ref\"",
"type": "text"
}
]
}
}
},
"description": {
"default_analyzer": "",
"dynamic": false,
"enabled": true,
"properties": {
"long": {
"enabled": true,
"dynamic": false,
"fields": [
{
"include_in_all": true,
"index": true,
"name": "long",
"type": "text"
}
]
},
"short": {
"enabled": true,
"dynamic": false,
"fields": [
{
"include_in_all": true,
"index": true,
"name": "short",
"type": "text"
}
]
}
}
},
"isVisible": {
"enabled": true,
"dynamic": false,
"fields": [
{
"include_term_vectors": true,
"index": true,
"name": "isVisible",
"type": "boolean"
}
]
},
"brandName": {
"enabled": true,
"dynamic": false,
"fields": [
{
"include_in_all": true,
"index": true,
"name": "brandName",
"type": "text"
}
]
},
"fobPriceMax": {
"enabled": true,
"dynamic": false,
"fields": [
{
"name": "fobPriceMax",
"store": true,
"type": "text"
}
]
},
"fobPriceMin": {
"enabled": true,
"dynamic": false,
"fields": [
{
"name": "fobPriceMin",
"store": true,
"type": "text"
}
]
},
"fobUnit": {
"enabled": true,
"dynamic": false,
"fields": [
{
"name": "fobUnit",
"store": true,
"type": "text"
}
]
},
"isActive": {
"enabled": true,
"dynamic": false,
"fields": [
{
"include_term_vectors": true,
"index": true,
"name": "isActive",
"type": "boolean"
}
]
},
"fobCurrency": {
"enabled": true,
"dynamic": false,
"fields": [
{
"name": "fobCurrency",
"store": true,
"type": "text"
}
]
},
"keywords": {
"enabled": true,
"dynamic": false,
"fields": [
{
"analyzer": "keyword",
"include_in_all": true,
"index": true,
"name": "keywords",
"type": "text"
}
]
},
"mainPicture": {
"enabled": true,
"dynamic": false,
"fields": [
{
"name": "mainPicture",
"store": true,
"type": "text"
}
]
},
"minOrderQuan": {
"enabled": true,
"dynamic": false,
"fields": [
{
"name": "minOrderQuan",
"store": true,
"type": "text"
}
]
},
"minOrderUnit": {
"enabled": true,
"dynamic": false,
"fields": [
{
"name": "minOrderUnit",
"store": true,
"type": "text"
}
]
},
"name": {
"enabled": true,
"dynamic": false,
"fields": [
{
"include_in_all": true,
"index": true,
"name": "name",
"store": true,
"type": "text"
}
]
},
"variationSerials": {
"enabled": true,
"dynamic": false,
"fields": [
{
"analyzer": "keyword",
"index": true,
"name": "variationSerials",
"type": "text"
}
]
}
}
}
}
},
"store": {
"indexType": "scorch",
"kvStoreName": "mossStore"
}
},
"sourceType": "couchbase",
"sourceName": "PTTTradeTest",
"sourceUUID": "7028f16e80f993f5d5f60c93e7eb1147",
"sourceParams": {},
"planParams": {
"maxPartitionsPerPIndex": 171,
"numReplicas": 0
},
"uuid": "7e334514e30a900d"}
我的搜索代码:
Product.searchAsync = function (term, categoryId, variations, limit, skip, sort) {
return new Promise(function (resolve, reject) {
var SearchQuery = Couchbase.SearchQuery;
var SearchFacet = Couchbase.SearchFacet;
var tqs = []
if (term) {
tqs.push(SearchQuery.match(term)); // It search in default field, here it's _all
}
if (categoryId) {
tqs.push(SearchQuery.term(categoryId).field("categories.$ref"));
}
if (variations) {
variations.map(v => tqs.push(SearchQuery.match(v).field("variationSerials")));
}
tqs.push(SearchQuery.booleanField(true).field("isActive"));
tqs.push(SearchQuery.booleanField(true).field("isVisible"));
var conjunction = SearchQuery.conjuncts(tqs);
var query = SearchQuery.new("product_search", conjunction);
query.addFacet("variations", SearchFacet.term("variationSerials", 100));
query.limit(limit);
query.skip(skip);
if (sort)
query.sort(sort);
query.fields(["name", "fobCurrency", "fobPriceMin", "fobPriceMax", "fobUnit", "mainPicture", "minOrderQuan", "minOrderUnit"]);
ottoman.bucket.query(query, (error, result, meta) => {
if (error) {
reject(error);
}
else {
var resultset = {
hits: result,
totalHits: meta.totalHits
};
resolve(resultset);
}
});
}.bind(this))
}
我的测试服务器具有 Intel® Xeon® 处理器 E7-4890 v2 2.80 GHz 和 12 gb RAM。在单个节点中,如果我使用“Moss”作为索引类型,我的服务每秒只能响应 300 个请求。如果我将索引类型更改为“Scorch”,它会增加到每秒 500-530 个请求。我相信这些都不是很好的结果。我究竟做错了什么?我怎样才能提高性能?