fields 自定義返回字段
{
//"_source": false,
//"_source": ["aa*", "bb*"]
//"_source": ["username"]
"fields": ["username"],
"aggs" : {
"genders" : {
"terms" : { "field": "username" }
}
}
}
基於時間範圍的分類彙總
{
//select yearmon(createtime) yearmon,method,status,count(*)
// from test group by yearmon,method,status
"size": 0,
"aggs" : {
"day_total" : {
"date_histogram":{
"field": "CreateTime",
"interval": "day",
"format": "yyyyMMdd"
},
"aggs": {
"method_total":{
"terms": {"field": "method"},
"aggs":{
"status_total":{
"terms": {"field": "status"}
}
}
}
}
}
}
}
Date detectionedit
If date_detection is enabled (default), then new string fields are checked to see whether their contents match any of the date patterns specified in dynamic_date_formats. If a match is found, a new date field is added with the corresponding format.
The default value for dynamic_date_formats is:
[“strict_date_optional_time”,”yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z”]
For example:
PUT my_index/my_type/1
{
"create_date": "2015/09/02"
}
GET my_index/_mapping
The create_date field has been added as a date field with the format: “yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z”.
Disabling date detectionedit
Dynamic date dection can be disabled by setting date_detection to false:
PUT my_index
{
"mappings": {
"my_type": {
"date_detection": false
}
}
}
PUT my_index/my_type/1
{
"create": "2015/09/02"
}
The create_date field has been added as a string field.
Customising detected date formatsedit
Alternatively, the dynamic_date_formats can be customised to support your own date formats:
PUT my_index
{
"mappings": {
"my_type": {
"dynamic_date_formats": ["MM/dd/yyyy"]
}
}
}
PUT my_index/my_type/1
{
"create_date": "09/25/2015"
}
Disabling automatic type creationedit
Automatic type creation can be disabled by setting the index.mapper.dynamic setting to false, either by setting the default value in the config/elasticsearch.yml file, or per-index as an index setting:
PUT /_settings
{
"index.mapper.dynamic":false
}
強制清除Elasticsearch中已刪除的文件
POST /_optimize?only_expunge_deletes=true
下面兩個設置可以用於控制清除時的處理速度,其中給出值是默認值,可以根據需求進行調整,具體請參見 Merge。 此外, 還可以臨時將所有索引的replica設置爲0,這樣只用針對Primary進行expunge,以減小I/O壓力。
PUT /{index}/_settings
{
"settings": {
"index.merge.policy.expunge_deletes_allowed": "10",
"index.merge.policy.max_merge_at_once_explicit" : "30"
}
}
檢查文檔是否存在
如果你想做的只是檢查文檔是否存在——你對內容完全不感興趣——使用 HEAD 方法來代替 GET 。 HEAD 請求不會返回響應
體,只有HTTP頭:
curl -i -XHEAD http://localhost:9200/website/blog/123
HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Content-Length: 0
curl -i -XHEAD http://localhost:9200/website/blog/124
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=UTF-8
Content-Length: 0
該API同樣也適合於檢查index,type是否存在
Elasticsearch權威指南精華章節
官方API接口文檔收集
內存性能優化方面
限制內存使用
https://www.elastic.co/guide/en/elasticsearch/guide/current/_limiting_memory_usage.htmlfielddata說明
https://www.elastic.co/guide/en/elasticsearch/reference/2.0/fielddata.html預熱fielddata
https://www.elastic.co/guide/en/elasticsearch/guide/current/preload-fielddata.html優化索引性能技巧
https://www.elastic.co/guide/en/elasticsearch/guide/current/indexing-performance.htmlDoc_values使用
https://www.elastic.co/guide/en/elasticsearch/guide/current/doc-values.html
Index模塊
- Index模塊之stroe
https://www.elastic.co/guide/en/elasticsearch/reference/1.7/index-modules-store.html - Index模塊之translog
https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-translog.html - Index模塊之merge
https://www.elastic.co/guide/en/elasticsearch/reference/1.7/index-modules-merge.html - Index Settings
https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html#index-modules-settings - Shard Allocation Filtering
https://www.elastic.co/guide/en/elasticsearch/reference/current/shard-allocation-filtering.html
Cluster模塊
- https://www.elastic.co/guide/en/elasticsearch/reference/2.1/modules-cluster.html
- Cluster Level Shard Allocation Cluster Level Shard Allocation lists the settings to control the allocation an rebalancing operations.
- Disk-based Shard Allocation explains how Elasticsearch takes available disk space into account, and the related settings.
- Shard Allocation Awareness Shard Allocation Awareness control how shards can be distributed across different racks or availability zones.
Shard Allocation Filtering Shard Allocation Filtering allows certain nodes or groups of nodes excluded from allocation so that they can be decommisioned.
Cluster Reroute The reroute command allows to explicitly execute a cluster reroute allocation command including specific commands.
API接口
連接查詢
https://www.elastic.co/guide/en/elasticsearch/reference/2.1/joining-queries.htmlbulk api
https://www.elastic.co/guide/en/elasticsearch/reference/2.1/docs-bulk.htmlindex api
https://www.elastic.co/guide/en/elasticsearch/reference/2.1/docs-index_.htmlupdate api
https://www.elastic.co/guide/en/elasticsearch/reference/1.7/docs-update.html搜索偏好(search preference)
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-preference.html分佈式存儲
https://www.elastic.co/guide/en/elasticsearch/guide/current/distributed-docs.html
分佈式搜索
https://www.elastic.co/guide/en/elasticsearch/guide/master/distributed-search.htmlCluster Update Settings
https://www.elastic.co/guide/en/elasticsearch/reference/1.7/cluster-update-settings.html_cat API
https://www.elastic.co/guide/en/elasticsearch/reference/2.2/cat-nodes.html
其它
腳本模塊
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html選項參數
https://www.elastic.co/guide/en/elasticsearch/reference/2.1/common-options.html