<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PUT /test_boolean
{   &quot;mappings&quot;: {
        &quot;shops&quot;: {
            &quot;properties&quot;: {
                &quot;shop_type&quot;: {
                    &quot;type&quot;: &quot;object&quot;,
                    &quot;dynamic&quot;: &quot;strict&quot;,
                    &quot;properties&quot;: {
                        &quot;dealer&quot;: {&quot;type&quot;: &quot;boolean&quot;},
                        &quot;seller&quot;: {&quot;type&quot;: &quot;boolean&quot;}
                    }
                }
            }
        }
    }
}

# THIS DOC SHOULD GET INDEXED
PUT test_boolean/shops/1
{
    &quot;shop_type&quot;: [  
        {   &quot;dealer&quot;: true, 
            &quot;seller&quot;: false
        }
    ]
}


#THIS DOC SHOULDNOT GET INDEXED. MAPPER EXCEPTION EXPECTED
PUT test_boolean/shops/2
{
    &quot;shop_type&quot;: [  
        {   &quot;dealer&quot;: true, 
            &quot;seller&quot;: &quot;No this not a seller&quot;
        }
    ]
}"><pre class="notranslate"><code class="notranslate">PUT /test_boolean
{   "mappings": {
        "shops": {
            "properties": {
                "shop_type": {
                    "type": "object",
                    "dynamic": "strict",
                    "properties": {
                        "dealer": {"type": "boolean"},
                        "seller": {"type": "boolean"}
                    }
                }
            }
        }
    }
}

# THIS DOC SHOULD GET INDEXED
PUT test_boolean/shops/1
{
    "shop_type": [  
        {   "dealer": true, 
            "seller": false
        }
    ]
}


#THIS DOC SHOULDNOT GET INDEXED. MAPPER EXCEPTION EXPECTED
PUT test_boolean/shops/2
{
    "shop_type": [  
        {   "dealer": true, 
            "seller": "No this not a seller"
        }
    ]
}
</code></pre></div>
<p dir="auto">Tried on latest: 1.7.1</p>
<p dir="auto">According to my usecase the second document should fail by Mapper Exception telling cannot match string "No this not a seller" to boolean type.</p>
<p dir="auto">I read though this <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-core-types.html#boolean" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-core-types.html#boolean</a><br>
The doc says any string is finally treated as True. But i can see the final persisted doc contains the string as well.</p>
<p dir="auto">GET test_boolean/shops/2</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
   &quot;_index&quot;: &quot;test_boolean&quot;,
   &quot;_type&quot;: &quot;shops&quot;,
   &quot;_id&quot;: &quot;2&quot;,
   &quot;_version&quot;: 1,
   &quot;found&quot;: true,
   &quot;_source&quot;: {
      &quot;shop_type&quot;: [
         {
            &quot;dealer&quot;: true,
            &quot;seller&quot;: &quot;No this not a seller&quot;
         }
      ]
   }
}"><pre class="notranslate"><code class="notranslate">{
   "_index": "test_boolean",
   "_type": "shops",
   "_id": "2",
   "_version": 1,
   "found": true,
   "_source": {
      "shop_type": [
         {
            "dealer": true,
            "seller": "No this not a seller"
         }
      ]
   }
}
</code></pre></div>
<p dir="auto">Is this a bug or a feature. If a feature, how can i circumvent this problem to enforce my usecase.</p>
<p dir="auto">Spinoff from <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="82949294" data-permission-text="Title is private" data-url="https://github.com/elastic/elasticsearch/issues/11437" data-hovercard-type="pull_request" data-hovercard-url="/elastic/elasticsearch/pull/11437/hovercard" href="https://github.com/elastic/elasticsearch/pull/11437">#11437</a>.</p>
<p dir="auto">Today, most boolean settings in Elasticsearch are parsed leniently<br>
using <code class="notranslate">Booleans.parseBoolean</code>, which interprets <code class="notranslate">0</code>, <code class="notranslate">no</code>, <code class="notranslate">off</code> and <code class="notranslate">false</code><br>
as <code class="notranslate">false</code>, else <code class="notranslate">true</code> for any random strings like <code class="notranslate">NO</code> or <code class="notranslate">OFF</code> or <code class="notranslate">foobar</code>, etc.</p>
<p dir="auto">I think this is dangerous: if the user has a typo for false, or maybe<br>
thinks "disabled" would also mean false, they silently get true.</p>
<p dir="auto">I think we should parse boolean settings strictly, maybe using this<br>
awesome project: <a href="https://github.com/rmuir/booleanparser">https://github.com/rmuir/booleanparser</a> so that the<br>
user gets a clear exception stating that the value is not recognized.</p>
<p dir="auto">Unfortunately this is a biggish project ... I think we'd need to take<br>
a similar approach to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="82949294" data-permission-text="Title is private" data-url="https://github.com/elastic/elasticsearch/issues/11437" data-hovercard-type="pull_request" data-hovercard-url="/elastic/elasticsearch/pull/11437/hovercard" href="https://github.com/elastic/elasticsearch/pull/11437">#11437</a>, where for back compat if we see<br>
un-parseable boolean settings from persisted places (cluster, index<br>
settings), we dynamically map them to true and log a warning.</p>