<p dir="auto"><strong>Elasticsearch version</strong>:<br>
2.3.3</p>
<p dir="auto"><strong>JVM version</strong>:<br>
8u91</p>
<p dir="auto"><strong>OS version</strong>:<br>
Debian Jessie and CentOS 7</p>
<p dir="auto"><strong>Description of the problem including expected versus actual behavior</strong>:</p>
<p dir="auto">Including a simple query string query with the NOT operator (hyphen) causes all documents to be returned.</p>
<p dir="auto"><strong>Steps to reproduce</strong>:</p>
<ol dir="auto">
<li>
<p dir="auto">Start from a fresh ElasticSearch instance</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="docker run -d -p 9200:9200 elasticsearch -Des.network.host=0.0.0.0"><pre class="notranslate"><code class="notranslate">docker run -d -p 9200:9200 elasticsearch -Des.network.host=0.0.0.0
</code></pre></div>
</li>
<li>
<p dir="auto">Load some data</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -XPUT localhost:9200/test_index -d '{&quot;settings&quot;: {&quot;index&quot; {&quot;number_of_shards&quot;: 3, &quot;number_of_replicas&quot;: 0}}}'
curl -XPOST localhost:9200/test_index/test_doc -d '{&quot;content&quot;: &quot;Buffalo&quot;}'
curl -XPOST localhost:9200/test_index/test_doc -d '{&quot;content&quot;: &quot;Buffalo, New York&quot;}'
curl -XPOST localhost:9200/test_index/test_doc -d '{&quot;content&quot;: &quot;Canada&quot;}'"><pre class="notranslate"><code class="notranslate">curl -XPUT localhost:9200/test_index -d '{"settings": {"index" {"number_of_shards": 3, "number_of_replicas": 0}}}'
curl -XPOST localhost:9200/test_index/test_doc -d '{"content": "Buffalo"}'
curl -XPOST localhost:9200/test_index/test_doc -d '{"content": "Buffalo, New York"}'
curl -XPOST localhost:9200/test_index/test_doc -d '{"content": "Canada"}'
</code></pre></div>
</li>
<li>
<p dir="auto">Verify normal querying works:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -XGET localhost:9200/test_index/test_doc/_search -d'
{
&quot;query&quot;: {
    &quot;simple_query_string&quot;: {
        &quot;query&quot;: &quot;Buffalo&quot;
    }
}
}'
# The two, correct results are returned"><pre class="notranslate"><code class="notranslate">curl -XGET localhost:9200/test_index/test_doc/_search -d'
{
"query": {
    "simple_query_string": {
        "query": "Buffalo"
    }
}
}'
# The two, correct results are returned
</code></pre></div>
</li>
<li>
<p dir="auto">Demonstrate queries with the NOT operator don't work:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
&quot;query&quot;: {
    &quot;simple_query_string&quot;: {
        &quot;query&quot;: &quot;Buffalo -New&quot;
    }
}
}'
# Here, all three documents are returned, including one without terms specified in the query."><pre class="notranslate"><code class="notranslate">{
"query": {
    "simple_query_string": {
        "query": "Buffalo -New"
    }
}
}'
# Here, all three documents are returned, including one without terms specified in the query.
</code></pre></div>
</li>
</ol>
<p dir="auto">I am creating via BulkRequestBuilder, doing</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="add(client.prepareIndex(...).setOpType(OpType.CREATE)"><pre class="notranslate"><code class="notranslate">add(client.prepareIndex(...).setOpType(OpType.CREATE)
</code></pre></div>
<p dir="auto">I have a test where I bulk insert and a subset of the objects inserted already exist. I then attach a listener to the bulk request, and expect to get .hasFailures() etc. (This is running vs an in memory server created in JUnit, if that makes any difference)</p>
<p dir="auto">Instead what happens is hasFailures() returns false, and the inserts silently fail (ie they appear in the requests() array with isFailed()==false, but aren't updated).</p>
<p dir="auto">One difference I do see in the listener is that the new objects have version==1 whereas the failed indexes have ==-3, eg (my duplicate objects start at "id51"):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="WORKED2: 29...id50...CREATE...{&quot;_id&quot;:&quot;id50&quot;,&quot;test_string&quot;:&quot;test_string250&quot;}...1
WORKED2: 30...id51...CREATE...{&quot;_id&quot;:&quot;id51&quot;,&quot;test_string&quot;:&quot;test_string251&quot;}...-3"><pre class="notranslate"><code class="notranslate">WORKED2: 29...id50...CREATE...{"_id":"id50","test_string":"test_string250"}...1
WORKED2: 30...id51...CREATE...{"_id":"id51","test_string":"test_string251"}...-3
</code></pre></div>
<p dir="auto">(for</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="System.out.println(&quot;WORKED2: &quot; + bir.getItemId() + &quot;...&quot; + bir.getId() + &quot;...&quot; + ir.opType().toString() + &quot;...&quot; + ir.source().toUtf8() + &quot;...&quot; + ir.version());"><pre class="notranslate"><code class="notranslate">System.out.println("WORKED2: " + bir.getItemId() + "..." + bir.getId() + "..." + ir.opType().toString() + "..." + ir.source().toUtf8() + "..." + ir.version());
</code></pre></div>
<p dir="auto">)</p>
<p dir="auto">I confirm the object is not updated in the DB, eg:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---------------- {&quot;_id&quot;:&quot;id50&quot;,&quot;test_string&quot;:&quot;test_string250&quot;} // (newly inserted object)
---------------- {&quot;_id&quot;:&quot;id51&quot;,&quot;test_string&quot;:&quot;test_string51&quot;} // (original object)"><pre class="notranslate"><code class="notranslate">---------------- {"_id":"id50","test_string":"test_string250"} // (newly inserted object)
---------------- {"_id":"id51","test_string":"test_string51"} // (original object)
</code></pre></div>
<p dir="auto">Any ideas what's going on here?</p>
<p dir="auto">(EDIT: note if i change from OpType.CREATE to OpType.INDEX then as expected I see versions 1 for new objects, 2 for updated objects, and the objects are updated in the DB)</p>
<p dir="auto">Is this because I'm using a listener and there's a second wave of verification that occurs after the onResponse()? I'm "happy" to use negative version to indicate "duplicate insert failure" if that's going to be consistent behavior.</p>
<p dir="auto">(Apologies if this behavior is explained somewhere, I couldn't find it!)</p>