- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 elasticsearch 索引中有几千个文档。文档有一些嵌套的集合。其中之一是“变体”的嵌套集合。其中一个文档的 JSON 结构是:
{
"id" : 1,
"name": "lollipop",
"model_name": "candy",
"variants": [
{
"id": 1000,
"taste": "orange",
"gross_price": 13,
"stock_quantity": 15
},
{
"id": 1001,
"taste": "apple",
"gross_price": 7,
"stock_quantity": 1
},
{
"id": 1002,
"taste": "bannana",
"gross_price": 9,
"stock_quantity": 13
},
,
{
"id": 1003,
"taste": "pinaple",
"gross_price": 19,
"stock_quantity": 10
},
... and more and more ...
],
... and more and more ...
}
我的店铺在一个页面上只显示了 48 个产品。我的索引共有 4800 种产品,所以我的商店有 100 页。
我在按价格排序时遇到问题。
在任何页面上,我想获得 stock_quantity 大于 1 的最低变体价格的下 48 种产品。为了获得最轻的结果 - 我正在按变体使用 inner_hits。然后我只得到符合我的条件的变体。
我写了一些 elasticsearch 查询(第一页):
GET myshop_index/product/_search
{
"from": 0,
"size": 48,
"sort": [
{
"variants.gross_price": {
"mode": "min",
"order": "asc",
"nested_path": "variants"
}
}
],
"_source": {
"excludes": [
"variants"
]
},
"query": {
"bool": {
"filter": [
{
"nested": {
"query": {
"bool": {
"must": [
{
"range": {
"variants.stock_quantity": {
"gt": 1
}
}
}
]
}
},
"path": "variants",
"inner_hits": {
"name": "variants",
"size": 10000
}
}
}
]
}
}
}
}
我有前 48 种产品及其变体,但这种排序不适用于我索引中的所有产品变体。这种排序方式如下:
但我需要得到这个场景:
有什么想法吗?
最佳答案
好的,我解决了我的问题。我找到了 Nested Sorting .这对我有用。尤其是第 5 点。 “sort子句中的nested_filter与主查询子句中的nested_filter是一样的,原因在后面解释。”然后再解释
关于sorting - Elasticsearch 通过分页按价格对 InnerHits 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46075605/
我的 elasticsearch 索引中有几千个文档。文档有一些嵌套的集合。其中之一是“变体”的嵌套集合。其中一个文档的 JSON 结构是: { "id" : 1, "name": "loll
我正在使用 NEST 2 客户端对我们的 Elasticsearch 执行查询。 我们有一个查询嵌套文档数组,并使用 .InnerHits() 在结果中包含嵌套文档的匹配项。 有没有办法将 Inner
我目前正在从 spring 数据 Elasticsearch 3.2.X 迁移到 4.0.0。 我一直依赖于通过使用现在已弃用的低级函数 通过原始 SearchResponse 类获取内部点击结果or
我是一名优秀的程序员,十分优秀!