【发布时间】:2019-07-16 07:52:18
【问题描述】:
我正在开发一个类似于购物车的应用程序,我们在其中存储产品及其元数据 (JSON),并且我们期望更快的搜索结果。 (预期的搜索结果应包含在产品 JSON 文档中任何位置具有搜索字符串的文档)
我们选择了 ElasticSearch(AWS 服务)来存储完整的产品 JSON。我们认为这对我们更快的搜索结果很有帮助。
但是当我尝试测试我的搜索端点时,单个请求需要 2 秒以上,如果我使用 Jmeter 发出 100 个并行请求,它会继续增加到 30 秒。 (这些查询时间来自应用程序日志,而不是来自 Jmeter 响应。)
这是我存储在 ElasticSearch 中的示例产品 JSON 和示例搜索字符串。
我认为我们以错误的方式使用 ES,请帮助我们以正确的方式实现它。
产品 JSON:
{
"dealerId": "D320",
"modified": 1562827907,
"store": "S1000",
"productId": "12345689",
"Items": [
{
"Manufacturer": "ABC",
"CODE": "V22222",
"category": "Electronics",
"itemKey": "b40a0e332190ec470",
"created": 1562828756,
"createdBy": "admin",
"metadata": {
"mfdDate": 1552828756,
"expiry": 1572828756,
"description": "any description goes here.. ",
"dealerName": "KrishnaKanth Sing, Bhopal"
}
}
]
}
搜索字符串:
krishna
更新:
我们每天收到多种产品的库存(具有不同 productIds 的单独 JSON),我们将它们存储在按日期索引的索引中(例如 products_20190715)。
在搜索时,我们正在搜索 products_* 索引。
我们正在使用JestClient 库从我们的SpringBoot 应用程序与ES 通信。
示例搜索查询:
{
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"simple_query_string": {
"query": "krishna*",
"flags": -1,
"default_operator": "or",
"lenient": true,
"analyze_wildcard": false,
"all_fields": true,
"boost": 1
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost": 1
}
}
],
"filter": [
{
"bool": {
"must": [
{
"bool": {
"should": [
{
"match_phrase": {
"category": {
"query": "Electronics",
"slop": 0,
"boost": 1
}
}
},
{
"match_phrase": {
"category": {
"query": "Furniture",
"slop": 0,
"boost": 1
}
}
},
{
"match_phrase": {
"category": {
"query": "Sports",
"slop": 0,
"boost": 1
}
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost": 1
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost": 1
}
},
{
"bool": {
"disable_coord": false,
"adjust_pure_negative": true,
"boost": 1
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost": 1
}
},
"sort": [
{
"modified": {
"order": "desc"
}
}
]
}
【问题讨论】:
-
您需要更详细地了解如何将此 JSON 存储为弹性文档。它在问题中的呈现方式,似乎您可能只有一个文档......?
-
@JamesThorpe,我已经更新了我的原始帖子。
-
@VenkatPapana 你能提供你的 ES JSON 查询吗
-
@AmitKhandelwal,更新了原帖中的查询
标签: elasticsearch amazon-elasticsearch jest-client