Elasticsearch compared to a traditional database
RelationalDB | Elasticsearch |
---|---|
Database | Indices |
Tables (tables) | types |
Row (row) | documents |
Columns | fields |
Elasticsearch data type
- String type:
text, keyword
- Value type:
long, integer, short, byte, double, float, half_float, scaled_float
- Date type:
date
- Boolean type:
boolean
- Binary type:
binary
- There is no dedicated array data type for Elasticsearch. By default, any field can contain zero or more values, but all values in the array must have the same data type. This is different from the set of objects that nested refers to. Arrays is just a collection of single-type arrays. In addition, there is no need for a special type class to define array types.
Basic operation
Create a typed index
PUT /test2
{
mappings: {
properties: {
name: {
type: 'text'}}}}/ / abandoned
PUT /test2
{
mappings: {
user: {
properties: {
name: {
type: 'text'
}
}
}
}
}
Copy the code
The developers of ES initially wanted users to understand that “index” was similar to “database” in an SQL database and that type was equivalent to a table. This is considered a bad analogy, leading to false assumptions. Because in SQL databases, tables are independent (after BC paradigm), columns in one table are not associated with columns with the same name in another table, but this is not the case for fields in mapping types, such as user and Tweet above, where both types have the user_name field. 1. In the ElasticSearch index, lucene solves this problem by creating a lucene field with the same name in different types. In other words, using the above example, the user_name field in user is stored in exactly the same field as the user_name field in tweet, and the two user_name fields must have the same definition in both types. For example, to operate uniformly on this field, The type of this field must be the same. So if you delete the “ID” field in the same index where user is stored as long, because tweet is stored as “keyword,” it might fail. 2. In addition, storing different entities with few or no common fields in the same index can lead to data sparseness and interfere with Lucene’s ability to effectively compress documents. For these reasons, the concept of multiple mapping types is removed from ES.
Query the type of the index field
GET /test2
Copy the code
participles
let result = await axios({
method: 'post'.url: 'http://localhost:9200/_analyze'.data: {
"analyzer": "ik_smart"."text": str
}
});
Copy the code
Special request format for ElasticSearch
Blog.csdn.net/sunshine050…