【发布时间】:2016-03-22 10:33:06
【问题描述】:
我的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
}]}
【问题讨论】:
-
您能否添加一个您希望此查询返回的示例文档?
-
在您的第一个查询中,您在未分析的字段上使用
match。它不会起作用。 -
@DrTyrsa 我也试过“term”,但同样的问题。
-
@mbudnik,如果你注意到 lineorder 里面有另一个嵌套数组,但我没有声明为嵌套。我已经尝试使用嵌套但也不起作用。两个查询都应该只返回第一个线序。
-
@Raphael 你想过滤
lineorders,而不是part2's?那么你应该使用内部点击elastic.co/guide/en/elasticsearch/reference/current/…
标签: elasticsearch nested-queries