Filter Query Not Working


(K.Samanth Kumar Reddy) #1

Hi,

I am newbie to elasticsearch. I have written the following two queries on my existing elasticsearch index.

Query 1:
{
"size" : 100,
"from" : 0,

"query": {
    "bool": {
        "must": [
            { "match": { "eu_name": "ARTEA AG REG TOSCANA EROGAZ AGRIC" }},
            {
                "nested": {
                    "path": "SUPPORT",

                    "query": {
                        "bool": {
                            "must": [
                                { "match": { "SUPPORT.ticket_id": "77098"}}
                            ]
                        }
                    }                        
                }
            }
        ]
    }
}

}

Query 2:

{
"size" : 100,
"from" : 0,

"query": {
    "bool": {
        "must": [
            { "match": { "eu_name": "ARTEA AG REG TOSCANA EROGAZ AGRIC" }},
            {
                "nested": {
                    "path": "SUPPORT",

                    "query": {
                        "bool": {
                            "must": [
                                { "match": { "SUPPORT.ticket_id": "77098"}}
                            ]
                        }
                    },

                    "filter": {
                        "range": {
                            "SUPPORT.closed_Dt": {
                                "gt": "2015-02-13"
                            }
                        }
                    }
                }
            }
        ]
    }
}

}

"Query 1" is giving the result having the 1 document. Here Query 1 is formed without applying the filter.
"Query 2" is giving the result having the 2 documents. Here Query 2 is formed by applying the filter.

I am wondering why the "Query 2" has given 2 document after applying the filter.

I am really wondering!!!

It would be greatly appreciated if any expert can throw some light on this magical problem.

Thank You!

Regards,
Samanth


(Adrien Grand) #2

Query 2 is malformed, it cannot provide both a query and a filter. It should look like this:

{
	"query": {
		"bool": {
			"must": [{
				"match": {
					"eu_name": "ARTEA AG REG TOSCANA EROGAZ AGRIC"
				}
			}, {
				"nested": {
					"path": "SUPPORT",

					"query": {
						"bool": {
							"must": [{
								"match": {
									"SUPPORT.ticket_id": "77098"
								}
							}],
							"filter": [{
								"range": {
									"SUPPORT.closed_Dt": {
										"gt": "2015-02-13"
									}
								}
							}]
						}
					}
				}
			}]
		}
	}
}

(K.Samanth Kumar Reddy) #3

Thank You!

Even this query did not work with my elasticsearch. Because I am using old version.
I have changed my elasticsearch version to latest. Now it is working.

Thank you!.

Regards,
Samanth


(system) #4