Data in: documents and indices
Elasticsearch是一个分布式文档存储。Elasticsearch不将信息存储为列数据,而是存储已序列化为JSON文档的复杂数据结构。当一个集群中有多个Elasticsearch节点时,存储的文档分布在整个集群中,可以从任何节点立即访问它们。
Elasticsearch is a distributed document store. Instead of storing information as rows of columnar data, Elasticsearch stores complex data structures that have been serialized as JSON documents. When you have multiple Elasticsearch nodes in a cluster, stored documents are distributed across the cluster and can be accessed immediately from any node.当搜索一个存储在es中的文档时,它会被使用索引在1秒内几乎实时搜索到。Elasticsearch使用一种称为倒排索引的数据结构,支持非常快速的全文搜索。倒排索引列出任何文档中出现的每个唯一单词,并标识每个单词所在的所有文档。
When a document is stored, it is indexed and fully searchable in near real-time—within 1 second. Elasticsearch uses a data structure called an inverted index that supports very fast full-text searches. An inverted index lists every unique word that appears in any document and identifies all of the documents each word occurs in.可以将索引看作是文档的优化过的集合,每个文档都是字段的集合,字段是包含数据的键-值对。默认情况下,Elasticsearch对每个字段中的所有数据进行索引,每个索引字段都有一个专用的优化数据结构。例如,文本字段存储在倒排索引中,数字和地理字段存储在BKD树中。使用每个字段的数据结构来组装和返回搜索结果的能力是Elasticsearch如此快速的原因。
An index can be thought of as an optimized collection of documents and each document is a collection of fields, which are the key-value pairs that contain your data. By default, Elasticsearch indexes all data in every field and each indexed field has a dedicated, optimized data structure. For example, text fields are stored in inverted indices, and numeric and geo fields are stored in BKD trees. The ability to use the per-field data structures to assemble and return search results is what makes Elasticsearch so fast.Elasticsearch还具有无模式的能力,这意味着可以对文档进行索引,而无需显式地指定如何处理文档中可能出现的每个不同字段。启用动态映射后,Elasticsearch将自动检测并向索引添加新字段。这种默认行为使您可以很容易地对数据进行索引和研究,只要开始对文档进行索引,Elasticsearch就会检测布尔值、浮点数和整数值、日期和字符串,并将它们映射到相应的Elasticsearch数据类型。
Elasticsearch also has the ability to be schema-less, which means that documents can be indexed without explicitly specifying how to handle each of the different fields that might occur in a document. When dynamic mapping is enabled, Elasticsearch automatically detects and adds new fields to the index. This default behavior makes it easy to index and explore your data—just start indexing documents and Elasticsearch will detect and map booleans, floating point and integer values, dates, and strings to the appropriate Elasticsearch datatypes.但是归根结底,你比Elasticsearch更了解你的数据以及如何使用它。你可以定义规则来控制动态映射,并显式定义映射来完全控制字段的存储和索引方式。
Ultimately, however, you know more about your data and how you want to use it than Elasticsearch can. You can define rules to control dynamic mapping and explicitly define mappings to take full control of how fields are stored and indexed.定义好想要的的映射使你能够:
Defining your own mappings enables you to:区分全文字符串字段和精确值字符串字段
Distinguish between full-text string fields and exact value string fields执行特定于语言的文本分析
Perform language-specific text analysis为部分匹配优化字段
Optimize fields for partial matching使用自定义的日期格式
Use custom date formats使用无法自动检测到的数据类型,如地理点和地理形状
Use data types such as geo_point and geo_shape that cannot be automatically detected为不同的目的,以不同的方式索引相同的字段通常是有用的。例如,你可能希望将字符串字段作为全文搜索的文本字段和作为排序或聚合数据的关键字字段建立索引。或者,您可以选择使用多个语言分析器来处理包含用户输入的字符串字段的内容。
It’s often useful to index the same field in different ways for different purposes. For example, you might want to index a string field as both a text field for full-text search and as a keyword field for sorting or aggregating your data. Or, you might choose to use more than one language analyzer to process the contents of a string field that contains user input.在索引期间应用于全文字段的分析链也会在搜索时使用。当您查询全文字段时,在索引中查找术语之前,查询文本将进行相同的分析。
The analysis chain that is applied to a full-text field during indexing is also used at search time. When you query a full-text field, the query text undergoes the same analysis before the terms are looked up in the index.




