本文主要介紹一下關於ES的boolean類型,希望對大家理解和使用ES有幫助。
Boolean Field 類型介紹:Boolea n Field是接受JSON true或者false的值,也接受可以被轉為true或者false的字符串
false值:false,"false",""
true值:true,"true"
例子:
curl -X PUT "localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d'{ "mappings": { "properties": { "is_published": { "type": "boolean" } } }}'curl -X POST "localhost:9200/my-index-000001/_doc/1?pretty" -H 'Content-Type: application/json' -d'{ "is_published": "true" }'curl -X GET "localhost:9200/my-index-000001/_search?pretty" -H 'Content-Type: application/json' -d'{ "query": { "term": { "is_published": true } }}'通過上面的例子可以看出,創建了一個名為my-index-000001的文檔,映射關係中有一個type為boolean的field為is_published。
下面是一個term查詢,匹配is_published為true的文檔。
curl -X POST "localhost:9200/my-index-000001/_doc/1?pretty" -H 'Content-Type: application/json' -d'{ "is_published": true}'curl -X POST "localhost:9200/my-index-000001/_doc/2?pretty" -H 'Content-Type: application/json' -d'{ "is_published": false}'curl -X GET "localhost:9200/my-index-000001/_search?pretty" -H 'Content-Type: application/json' -d'{ "aggs": { "publish_state": { "terms": { "field": "is_published" } } }, "script_fields": { "is_published": { "script": { "lang": "painless", "source": "doc[\u0027is_published\u0027].value" } } }}'boolean Field的參數列表下面是所列的參數列表是boolean field所接受的:
boost
doc_values
index
null_value
store
meta