Elasticsearch: Difference between revisions
Jump to navigation
Jump to search
m (Planetoid moved page Elastic search to Elasticsearch) |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 123: | Line 123: | ||
== Select particular data from index or table (exact match) == | == Select particular data from index or table (exact match) == | ||
Elasticsearch<ref>[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html Get index API | Elasticsearch Guide [8.15] | Elastic]</ref> | Elasticsearch<ref>[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html Get index API | Elasticsearch Guide [8.15] | Elastic]</ref> | ||
<pre> | <pre> | ||
GET /MY_INDEX/_search/?q=_id:1 | GET /MY_INDEX/_search/?q=_id:1 | ||
| Line 134: | Line 133: | ||
FROM MY_TABLE | FROM MY_TABLE | ||
WHERE id = 1 | WHERE id = 1 | ||
</pre> | |||
== Select particular data from index or table (partial match) == | |||
Elasticsearch<ref>[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html Boolean query | Elasticsearch Guide [8.15] | Elastic]</ref> | |||
<pre> | |||
GET /MY_INDEX/_search | |||
{ | |||
"query": { | |||
"bool": { | |||
"should": [ | |||
{ | |||
"match": { | |||
"field1": "NVIDIA" | |||
} | |||
} | |||
] | |||
} | |||
} | |||
} | |||
</pre> | |||
MySQL | |||
<pre> | |||
SELECT * | |||
FROM MY_TABLE | |||
WHERE field1 LIKE "%NVIDIA%" | |||
</pre> | </pre> | ||
Latest revision as of 16:46, 15 October 2024
Concept mapping[edit]
| MySQL (RDBMS) | Elasticsearch | Excel | Example Value (Bookstore) |
|---|---|---|---|
| Table | Index | Worksheet | books |
| Row | Document | Row | { "id": 1, "title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "price": 9.99 } |
| Field | Field | Column | title |
| Schema | Mapping | Column Headers | {
"properties": {
"title": { "type": "text" },
"author": { "type": "keyword" },
"price": { "type": "float" }
}
} |
| SQL | DSL | Formulas/Filters | SQL: SELECT * FROM books WHERE author = 'F. Scott Fitzgerald'
DSL: { "query": { "term": { "author": "F. Scott Fitzgerald" } } } Excel: Filter column "author" for "F. Scott Fitzgerald" |
Count the number of documents[edit]
Elasticsearch: Count API | Elasticsearch Guide [8.15 Elastic]
GET /MY_INXEX/_count
MySQL MySQL :: MySQL 8.4 Reference Manual :: 5.3.4.8 Counting Rows
SELECT COUNT(*) FROM MY_TABLE
Truncate the index or table[edit]
Elasticsearch: Delete API | Elasticsearch Guide [8.15 | Elastic][1]
DELETE /MY_INXEX/
MySQL MySQL :: MySQL 8.4 Reference Manual :: 15.1.37 TRUNCATE TABLE Statement
TRUNCATE MY_TABLE
Create the index or table[edit]
PUT /MY_INXEX
{
"mappings": {
"properties": {
"id": { "type": "keyword" },
"field1": { "type": "text" }
}
}
}
MySQL[5]
CREATE TABLE MY_TABLE ( id INT AUTO_INCREMENT PRIMARY KEY, field1 TEXT ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Select all data from index or table[edit]
Elasticsearch[6]
GET /MY_INDEX/_search/?size=1000&pretty=true
MySQL[7]
SELECT * FROM MY_TABLE LIMIT 1000
or
SELECT * FROM MY_TABLE
Select particular data from index or table (exact match)[edit]
Elasticsearch[8]
GET /MY_INDEX/_search/?q=_id:1
MySQL[9]
SELECT * FROM MY_TABLE WHERE id = 1
Select particular data from index or table (partial match)[edit]
Elasticsearch[10]
GET /MY_INDEX/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"field1": "NVIDIA"
}
}
]
}
}
}
MySQL
SELECT * FROM MY_TABLE WHERE field1 LIKE "%NVIDIA%"
References[edit]
- ↑ python - Truncate index in elasticsearch - Stack Overflow
- ↑ Create index API | Elasticsearch Guide [8.15 | Elastic]
- ↑ Elasticsearch Keyword VS. Text - Strings Types Explained
- ↑ Field data types | Elasticsearch Guide [8.15 | Elastic]
- ↑ MySQL :: MySQL 8.4 Reference Manual :: 15.1.20 CREATE TABLE Statement
- ↑ Get index API | Elasticsearch Guide [8.15 | Elastic]
- ↑ MySQL :: MySQL 8.4 Reference Manual :: 5.3.4.1 Selecting All Data
- ↑ Get index API | Elasticsearch Guide [8.15 | Elastic]
- ↑ MySQL :: MySQL 8.4 Reference Manual :: 5.3.4.2 Selecting Particular Rows
- ↑ Boolean query | Elasticsearch Guide [8.15 | Elastic]