Elasticsearch: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
== Concept mapping ==
<table class="wikisort" border="1">
            <tr>
                <th>MySQL (RDBMS)</th>
                <th>Elasticsearch</th>
                <th>Excel</th>
                <th>Example Value (Bookstore)</th>
            </tr>
            <tr>
                <td>Table</td>
                <td>Index</td>
                <td>Worksheet</td>
                <td>books</td>
            </tr>
            <tr>
                <td>Row</td>
                <td>Document</td>
                <td>Row</td>
                <td class="code">{ "id": 1, "title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "price": 9.99 }</td>
            </tr>
            <tr>
                <td>Field</td>
                <td>Field</td>
                <td>Column</td>
                <td>title</td>
            </tr>
            <tr>
                <td>Schema</td>
                <td>Mapping</td>
                <td>Column Headers</td>
                <td class="code"><pre>{
    "properties": {
        "title": { "type": "text" },
        "author": { "type": "keyword" },
        "price": { "type": "float" }
    }
}</pre></td>
            </tr>
            <tr>
                <td>SQL</td>
                <td>DSL</td>
                <td>Formulas/Filters</td>
                <td class="code">SQL: SELECT * FROM books WHERE author = 'F. Scott Fitzgerald'
DSL: { "query": { "term": { "author": "F. Scott Fitzgerald" } } }
Excel: Filter column "author" for "F. Scott Fitzgerald"</td>
            </tr>
    </table>


== Count the number of documents ==
== Count the number of documents ==

Revision as of 16:04, 15 October 2024

Concept mapping

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

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

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

Elasticsearch[2][3][4]

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

Elasticsearch[6]

GET /MY_INDEX/_search/?size=1000&pretty=true


MySQL[7]

SELECT * 
FROM MY_TABLE
LIMIT 1000

or

SELECT * 
FROM MY_TABLE

References