1

My nested_filter dont work, even my nested query. I'have create a mapping like this:

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"}
                        }
                 }
            }
}
}
}
}
}

But when I query it the way under it returns all document.

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"}}
                ]
        }}}}
      ]
}}
}'

or this way

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
          }
        }
      }
    }
  }
}'

What I'm doing wrong? I would like to query nested fields not parent/child, because my data is too big to link the child to parent.

My data is something like this:

{
    "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
            }]}
10
  • 1
    Can you add an example document you expect this query to return? Commented Mar 22, 2016 at 10:40
  • 1
    In your first query you are using match on not analyzed fields. It won't work. Commented Mar 22, 2016 at 11:15
  • @DrTyrsa I have tried "term" too, but same problem. Commented Mar 22, 2016 at 11:31
  • @mbudnik, If you notice the lineorder has another nested array inside it, but I've not declared as nested. I've tried it with nested but doesn't work too. Both queries should return just the first lineorder. Commented Mar 22, 2016 at 11:33
  • @Raphael Do you want to filter lineorders, not part2's? Then you should use inner hits elastic.co/guide/en/elasticsearch/reference/current/… Commented Mar 22, 2016 at 11:46

1 Answer 1

1

If you want to filter lineorders themselves you should use inner hits.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.