gpt4 book ai didi

elasticsearch - 在ElasticSearch上查询嵌套文档

转载 作者:行者123 更新时间:2023-12-02 23:31:19 25 4
gpt4 key购买 nike

我的nested_filter不起作用,即使我的嵌套查询也是如此。
我已经创建了这样的映射:

curl -XPUT 'localhost:9200/i_part' -d '
{
"mappings": {
"part2": {
"properties": {
"p_name": {
"type": "string", "index": "not_analyzed"
},
"lineorder": {
"type": "nested",
"properties": {
"lo_quantity": {"type":"integer"},
"lo_discount": {"type":"integer"},
"lo_shippriority": {"type": "string", "index": "not_analyzed"},
"lo_shipmode": {"type": "string", "index": "not_analyzed"},
"customer"{
"properties":{
"c_name": {"type": "string", "index": "not_analyzed"}
}
}
}
}
}
}
}
}

但是当我查询它下面的方式时会返回所有文档。
curl -XPOST 'localhost:9200/i_part/part2/_search?pretty' -d '
{
"query": {
"filtered": {
"filter": {
"nested" : {
"path" : "lineorder",
"filter": {
"and": [
{
"match" : {
"lineorder.lo_shipmode":"RAIL|"
}
},
{
"match" : {
"lineorder.lo_orderpriority":"1-URGENT"
}
}
]
}
}
}
}
},
"query": {
"bool": {
"must": [
{ "match": { "p_partkey": 1 }},
{
"nested": {
"path": "lineorder",
"query": {
"bool": {
"must": [
{"match": {"lineorder.lo_shipmode":"RAIL|"}},
{"match" : {"lineorder.lo_orderpriority":"1-URGENT"}}
]
}}}}
]
}}
}'

或者这样
curl -XGET 'localhost:9200/i_part/part2/_search?pretty' -d '
{
"query": {
"nested": {
"path": "lineorder",
"filter": {
"range": {
"lineorder.lo_discount": {
"gte": 2,
"lt": 4
}
}
}
}
},
"sort": {
"lineorder.lo_discount": {
"order": "asc",
"nested_filter": {
"range": {
"lineorder.lo_discount": {
"gte": 2,
"lt": 4
}
}
}
}
}
}'

我做错了什么?我想查询嵌套字段而不是父/子,因为我的数据太大,无法将子链接到父。

我的数据是这样的:
{
"p_name": "lace spring",
"lineorder": [{
"customer": [{
"c_name": "Customer#000014704",
}],
"lo_quantity": 49,
"lo_orderpriority": "1-URGENT",
"lo_discount": 3,
"lo_shipmode": "RAIL|",
"lo_tax": 0
}, {
"customer": [{
"c_name": "Customer#000026548",
}],
"lo_quantity": 15,
"lo_orderpriority": "3-MEDIUM",
"lo_discount": 10,
"lo_shipmode": "SHIP|",
"lo_tax": 0
}]}

最佳答案

如果您想自己过滤lineorder,则应使用inner hits

关于elasticsearch - 在ElasticSearch上查询嵌套文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36152005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com