Elasticsearch随笔02

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权威指南精华章节

  • 分布式集群
    http://download.csdn.net/detail/xtjsxtj/9400206

  • 分布式存储
    http://download.csdn.net/detail/xtjsxtj/9400188

  • 处理冲突
    http://download.csdn.net/detail/xtjsxtj/9398862

  • 分布式搜索
    http://download.csdn.net/detail/xtjsxtj/9400198

官方API接口文档收集

内存性能优化方面

  • 限制内存使用
    https://www.elastic.co/guide/en/elasticsearch/guide/current/_limiting_memory_usage.html

  • fielddata说明
    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.html

  • Doc_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.html

  • bulk api
    https://www.elastic.co/guide/en/elasticsearch/reference/2.1/docs-bulk.html

  • index api
    https://www.elastic.co/guide/en/elasticsearch/reference/2.1/docs-index_.html

  • update 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.html

  • Cluster 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

模板

  • 动态映射
    https://www.elastic.co/guide/en/elasticsearch/reference/2.1/dynamic-mapping.html
  • templates
    https://www.elastic.co/guide/en/elasticsearch/reference/2.1/indices-templates.html

你可能感兴趣的:(Elasticsearch随笔02)