Should combining bool queries does not works

I have this query in Elasticsearch 1.4.4:

`GET my_jobs/type_job/_search

{   "fields": [
   "id","user","state","start_time","end_time"
], 
    "query": {
        "bool": {
            "must": [
                
                {"term": {"user": {"value": "oid:user:id"}}},
                {"term": {"id": {"value": "oid:job:301:7544:1"}}}
               
                
                ], 
            "must_not": [
                {"term": {"state": {"value": "queued"}}}, 
                {"term": {"queue": {"value": "desktop.q"}}}], 
            "should": [
                {"bool": {
                    "must": [
                        {"term": {"state": {"value": "finished"}}}, 
                        {"range": {"start_time": {"lt": 1460930400}}}, 
                        {"range": {"end_time":   {"gt": 1459461600}}}]
                    }}, 
                {"bool": {
                    "must": [
                        {"term": {"state": {"value": "started"}}}, 
                        {"range": {"start_time": {"lt": 1460930400}}}]}}
            ]
        }
    }
}

But I am obtaining this:

{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 8.948642,
      "hits": [
         {
            "_index": "my_jobs",
            "_type": "type_job",
            "_id": "oid:job:301:7544:1",
            "_score": 8.948642,
            "fields": {
               "id": [
                  "oid:job:301:7544:1"
               ],
               "state": [
                  "finished"
               ],
               "start_time": [
                  1460980655
               ],
               "end_time": [
                  1460982464
               ],
               "user": [
                  "oid:user:id"
               ]
            }
         }
      ]
   }
}

But in my opinion this is not working correctly because this condition does not true:

 "should": [
                    {"bool": {
                        "must": [
                            {"term": {"state": {"value": "finished"}}}, 
                            {"range": {"start_time": {"lt": 1460930400}}}, 
                            {"range": {"end_time":   {"gt": 1459461600}}}]
                        }}, 

and

"start_time": [ 1460980655 ] > 1460930400 and not "start_time": [ 1460980655 ] < 1460930400 how we specify in the query at the begining.

Hi,

Clauses you specify under should don't necessarily have to match a doc for it to return in the result. A should-clause that matches will increase that documents score, so it will be ranked higher in the results. If the condition you are describing in the should clause needs to be true for all documents that are returned, it somehow needs to go into the mustclause.

Look at minimum_should_match. The default is tricky, I believe it is 0 if
there are must clauses and 1 if there aren't.

At the end I changed my query, if before I have this:

A and (not B) and (C or D)

now with the new change I did:

(C and (A and (not B)) or (D and (A and (not B))

and in this way aparently works correctly. Finally my query is written so:

"query": {
        "bool": {
            "must": [
                
                {"term": {"user": {"value": "oid:user:id"}}},
                {"term": {"id": {"value": "oid:job:301:7544:1"}}}
               
                
                ], 
            "must_not": [
                {"term": {"state": {"value": "queued"}}}, 
                {"term": {"queue": {"value": "desktop.q"}}}], 
            "should": [
                {"bool": {
                    "must": [
                        {"term": {"state": {"value": "finished"}}}, 
                        {"range": {"start_time": {"lt": 1460930400}}}, 
                        {"range": {"end_time":   {"gt": 1459461600}}}],

                     "must": [                
                        {"term": {"user": {"value": "oid:user:id"}}},
                       {"term": {"id": {"value": "oid:job:301:7544:1"}}}], 

                   "must_not": [
                        {"term": {"state": {"value": "queued"}}}, 
                       {"term": {"queue": {"value": "desktop.q"}}}]
                  }}, 
                {"bool": {
                    "must": [
                        {"term": {"state": {"value": "started"}}}, 
                        {"range": {"start_time": {"lt": 1460930400}}}]}}],

                  "must": [                
                        {"term": {"user": {"value": "oid:user:id"}}},
                       {"term": {"id": {"value": "oid:job:301:7544:1"}}}], 

                   "must_not": [
                        {"term": {"state": {"value": "queued"}}}, 
                       {"term": {"queue": {"value": "desktop.q"}}}]


                   
        }
    }

Thanks for sharing your results.

Thanks to you