簡體   English   中英

在 ElasticSearch 上查詢嵌套文檔

[英]Query nested documents on ElasticSearch

我的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本身,您應該使用內部 hits

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM