title: NestedQuery in BoolQuery using Java API
body: <p>I'm trying to understand how query in EL works, with lots of problems to be honest.</p>
  
  <p>Here my documents with properties:</p>
  
  <pre><code>{"statusError":null,
  "fileHash":"da8620bad21685c5e385fb1b43a7e744",
  "project":{"id":7687},
  "error":null,
  "ocrFile64":"JVBERi0xL...."
  "isInElastic":false,
  "originalName":"test.pdf",
  "lastUpdated":"2018-10-18T12:47:59Z",
  "dateCreated":"2018-10-18T12:40:19Z",
  "ocrAvailable":true,
  "attachment":{"date":"2018-07-05T07:20:06Z",
  "content_type":"application/pdf",
  "language":"en","title":"Untitled",
  "content":"blah blah blahblahblahblahblah"
  "company":{"id":1},
  "id":25850,
  "tag":[{"id":3},{"id":2}],
  "contentType":"application/pdf",
  "imageHash":"",
  "label":null,
  "size":47680,
  "user":{"id":7563},
  "md5":[100,97,56,54,50,48,98,97,100,50,49,54,56,53,99,53,101,51,56,53,102,98,49,98,52,51,97,55,101,55,52,52],
  "status":{"name":"CLASSIFIED"}}
  </code></pre>
  
  <p>EL has Ingest Module plug in installed for uploading content of file. Indeed the pipeline is ocrFile64 and the content of file is inside content properties.</p>
  
  <p>What I'm trying to do is pretty simple, I'd like to make a query like: give me all the document where originalName contains "test" and user.id is equal to 1 and content contains "blah".</p>
  
  <p>So far I have written this:</p>
  
  <pre><code>client = new RestHighLevelClient(builder)
  SearchRequest searchRequest = new SearchRequest("testEL")
  searchRequest.types("test")
  SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
  searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS))
  BoolQueryBuilder boolQuery = new BoolQueryBuilder();
  
  boolQuery.filter(new MatchPhrasePrefixQueryBuilder("originalName", "test"))
  
  boolQuery.filter(new NestedQueryBuilder("user", new MatchQueryBuilder("user.id", "1"), ScoreMode.None))
  
  boolQuery.filter(new MatchPhrasePrefixQueryBuilder("content", "blah"))
  
  searchSourceBuilder.query(boolQuery)
  searchRequest.source(searchSourceBuilder)
  SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
  </code></pre>
  
  <p>If I query just the orignalName it works. If I add the content not anymore, if I add the nested query it results in an error:</p>
  
  <pre><code>org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
  </code></pre>
  
  <p>Thanks</p>
  
  <p>Here the mapping:</p>
  
  <pre><code>{
    "mapping": {
      "test": {
        "properties": {
          "attachment": {
            "properties": {
              "content": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "content_length": {
                "type": "long"
              },
              "content_type": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "date": {
                "type": "date"
              },
              "language": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "title": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "company": {
            "properties": {
              "id": {
                "type": "long"
              }
            }
          },
          "contentType": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "dateCreated": {
            "type": "date"
          },
          "fileHash": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "id": {
            "type": "long"
          },
          "imageHash": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "isClassified": {
            "type": "boolean"
          },
          "isInElastic": {
            "type": "boolean"
          },
          "label": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "lastUpdated": {
            "type": "date"
          },
          "md5": {
            "type": "long"
          },
          "ocrAvailable": {
            "type": "boolean"
          },
          "ocrFile64": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "originalName": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "project": {
            "properties": {
              "id": {
                "type": "long"
              }
            }
          },
          "size": {
            "type": "long"
          },
          "status": {
            "properties": {
              "enumType": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "storageName": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "tag": {
            "properties": {
              "id": {
                "type": "long"
              }
            }
          },
          "user": {
            "properties": {
              "id": {
                "type": "long"
              }
            }
          }
        }
      }
    }
  }
  </code></pre>