es 笔记 2

8 篇文章 0 订阅

### only focus on use

### abstraction layer separate the representation

### Elasticsearch 版本基于7.10

安装 配置 mapping analyzer template

- 安装es
- 配置es


```
配置的优先级
Transient setting
Persistent setting
elasticsearch.yml setting
Default setting value
```

    - jvm配置
    - 安全配置
    
- 分析


```
两个用途:
- 将文档拆分为单词
2. 将高级搜索中的string拆分为单词
The index analysis module acts as a configurable registry of analyzers that can be used in order to convert a string field into individual terms which are:

added to the inverted index in order to make the document searchable
used by high level queries such as the match query to generate search terms.
```

- mapping


```
主要作用:包含什么字段,字段类型,字段是否以全文本存储,新加入的字段如何指定类型等
Mapping is the process of defining how a document, and the fields it contains, are stored and indexed. For instance, use mappings to define:

which string fields should be treated as full text fields.
which fields contain numbers, dates, or geolocations.
the format of date values.
custom rules to control the mapping for dynamically added fields.

元数据字段包括:
Examples of metadata fields include the document’s _index, _id, and _source fields.

注意:
Before 7.0.0, the mappings definition used to include a type name.

```
    1. 阻止mapping爆炸
    2. 动态mapping使我们不用定义字段就可以存储
    
    Fields and mapping types do not need to be defined before being used. Thanks to dynamic mapping, new field names will be added automatically, just by indexing a document.
    
    3. explicit mappings
    
```
curl -X PUT "localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "properties": {
      "age":    { "type": "integer" },  
      "email":  { "type": "keyword"  }, 
      "name":   { "type": "text"  }     
    }
  }
}
'

添加字段
curl -X PUT "localhost:9200/my-index-000001/_mapping?pretty" -H 'Content-Type: application/json' -d'
{
  "properties": {
    "employee-id": {
      "type": "keyword",
      "index": false
    }
  }
}
'

改变字段类型
Changing an existing field could invalidate data that’s already indexed

查看mapping
curl -X GET "localhost:9200/my-index-000001/_mapping?pretty"

查看某个字段的mapping
curl -X GET "localhost:9200/my-index-000001/_mapping/field/employee-id?pretty"


```

    4. 移除type Indices created in Elasticsearch 7.0.0 or later no longer accept a _default_ mapping
    5. In 7.0, _doc represents the endpoint name instead of the document type
    
```
使用_doc代替type
curl -X PUT "localhost:9200/my-index-000001/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "foo": "baz"
}
'

```

    6. 数据类型
    
    you can index strings to both text and keyword fields. However, text field values are analyzed for full-text search while keyword strings are left as-is for filtering and sorting.
    
    Currently, the only type family is keyword, which consists of the keyword, constant_keyword, and wildcard field types
    
    
```
Keywords
The keyword family, including keyword, constant_keyword, and wildcard.
```


```
使用join定义父子关系
join
Defines a parent/child relationship for documents in the same index.
```


```
加和数据类型
Aggregate data types
histogram
Pre-aggregated numerical values.
```


```
多字段:比如将字段定义两个,一个为text用于全文检索(带分词),一个定义为keyword用于排序或者加和(不分词)
Multi-fields
It is often useful to index the same field in different ways for different purposes. For instance, a string field could be mapped as a text field for full-text search, and as a keyword field for sorting or aggregations
```


```
histogram

A values array of double numbers, representing the buckets for the histogram. These values must be provided in ascending order.
A corresponding counts array of integer numbers, representing how many values fall into each bucket. These numbers must be positive or zero.

```


```
元数据字段

_field_names: This field was used by the exists query 

```


```
Mapping parameters

analyzer:
Only text fields support the analyzer mapping parameter.
有两个地方可以使用:
1.索引文本
2.解析查询的文本
The analyzer parameter specifies the analyzer used for text analysis when indexing or searching a text field.

We recommend testing analyzers before using them in production. See Test an analyzer.


```


```
mapping与setting的关系
mapping主要是索引的字段的信息
setting主要为索引本身的信息:包括副本数,索引搜索的最大值等。
至于分析器为什么放在setting中,而不放在mapping的具体的文本字段中,还不是很清楚?
```


```
abstraction layer & 垂直屏障

动态模板    |
============|
动态mapping | 静态mapping(严格mapping)
=======================================
         mapping

The automatic detection and addition of new fields is called dynamic mapping. The dynamic mapping rules can be customised to suit your purposes with:

动态字段mapping和动态模板:
Dynamic field mappings
The rules governing dynamic field detection.
Dynamic templates
Custom rules to configure the mapping for dynamically added fields.

星号
* may also be used in order to match all data types.

```

- 分析


```
Elasticsearch performs text analysis when indexing or searching text fields.

character filters -----流----> tokenizer ------流---> token filters ---->

```


```
Text analysis occurs at two times:

Index time
When a document is indexed, any text field values are analyzed.
Search time
When running a full-text search on a text field, the query string (the text the user is searching for) is analyzed.

index的分析器 or search的分析器
index analyzer or search analyzer

```


```
analyze api

curl -X POST "localhost:9200/_analyze?pretty" -H 'Content-Type: application/json' -d'
{
  "analyzer": "whitespace",
  "text":     "The quick brown fox."
}
'


```


```
normalizers标准化器

```

- index template

Index templates define settings and mappings that you can automatically apply when creating new indices. Elasticsearch applies templates to new indices based on an index pattern that matches the index name.

An index template is a way to tell Elasticsearch how to configure an index when it is created.

Index templates can contain a collection of component templates, as well as directly specify settings, mappings, and aliases.


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值