Json 弹性嵌套查询-仅显示前两个内部命中
如何更改查询以仅显示orderbook中的5个首批订单 我的数据结构是这样的。Order是嵌套类型Json 弹性嵌套查询-仅显示前两个内部命中,json,
elasticsearch,nested,kibana,json-query,Json,
elasticsearch,Nested,Kibana,Json Query,如何更改查询以仅显示orderbook中的5个首批订单 我的数据结构是这样的。Order是嵌套类型 Orderbook |_ Orders 这是我的问题 GET /orderindex/_search { "size": 10, "query": { "term": { "_type": "orderbook" } } } 这就是结果 { "took": 2, "timed_out": false,
Orderbook
|_ Orders
这是我的问题
GET /orderindex/_search
{
"size": 10,
"query": {
"term": { "_type": "orderbook" }
}
}
这就是结果
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 10,
"max_score": 1,
"hits": [
{
"_index": "orderindex",
"_type": "orderbook",
"_id": "1",
"_score": 1,
"_source": {
"id": 1,
"exchange": "Exch1",
"label": "USD/CAD",
"length": 40,
"timestamp": "5/16/2018 4:33:31 AM",
"orders": [
{
"pair1": "USD",
"total": 0.00183244,
"quantity": 61,
"orderbookId": 0,
"price": 0.00003004,
"exchange": "Exch1",
"id": 5063,
"label": "USD/CAD",
"pair2": "CAD",
},
{
"pair1": "USD",
"total": 0.0231154,
"quantity": 770,
"orderbookId": 0,
"price": 0.00003002,
"exchange": "Exch1",
"id": 5064,
"label": "USD/CAD",
"pair2": "CAD",
},
...
..
.
另外,我如何通过标签名查询两个特定的订单,并仅检索前两个订单
我现在发送这个查询,但问题是它返回了包括所有订单在内的订单簿,然后它只返回2个以上的内部点击。如何仅返回2个内部点击,而不返回来自查询第一部分的orderbook的所有订单
GET /orderindex/_search
{
"query": {
"bool": {
"must": [
{
"term": { "_type": "orderbook" }
},
{
"nested": {
"path": "orders",
"query": {
"match_all": {}
},
"inner_hits": {
"size": 2
}
}
}
]
}
}}
内部点击支持以下选项:
size
每次内部点击返回的最大点击数。默认情况下
返回前三个匹配的命中率
这基本上意味着,通过使用类似的查询,您可以做到这一点
{
"query": {
"bool": {
"must": [
{
#replace this one with your query for orderbook
"term": {
"user": "kimchy"
}
},
{
"nested": {
"path": "orders",
"query": {
"match_all": {}
},
"inner_hits": {
"size": 3 #we asks for only 3 inner hits
}
}
}
]
}
}
}
人们还可以通过这样做来了解结果:
"_source": {
"includes": [ "obj1.*", "obj2.*" ],
"excludes": [ "*.description" ]
}
对于订单-排除订单可能很有用。*
有关这项计划的更多资料-
内部点击支持以下选项:
size
每次内部点击返回的最大点击数。默认情况下
返回前三个匹配的命中率
这基本上意味着,通过使用类似的查询,您可以做到这一点
{
"query": {
"bool": {
"must": [
{
#replace this one with your query for orderbook
"term": {
"user": "kimchy"
}
},
{
"nested": {
"path": "orders",
"query": {
"match_all": {}
},
"inner_hits": {
"size": 3 #we asks for only 3 inner hits
}
}
}
]
}
}
}
人们还可以通过这样做来了解结果:
"_source": {
"includes": [ "obj1.*", "obj2.*" ],
"excludes": [ "*.description" ]
}
对于订单-排除订单可能很有用。*
关于这个的更多信息-这正是我想要的。tks!我用您建议的查询更新了上面的代码,但执行时的问题是,它只在返回包含其中所有订单的所有OrderBook之后返回2个内部命中,然后返回2个内部命中。我怎么能只保留订单簿和每个订单的2个内部点击?这正是我想要的。tks!我用您建议的查询更新了上面的代码,但执行时的问题是,它只在返回包含其中所有订单的所有OrderBook之后返回2个内部命中,然后返回2个内部命中。我怎样才能只保留订单簿和每个订单的2个内部点击?