Menu

Elasticsearch: The Very Basics
📰

Elasticsearch: The Very Basics

DEV Community: elasticsearch·Kaziu·1 day ago
#bUjUBZT4
#devtoelasticsearch#devto#dev#type#deal
Long article (295 words) — no AI summary yet.
Reading 0:00
15s threshold

Kaziu

Posted on Nov 16

Edited on Nov 16

(Notes for myself)

Compared with MySQL

MySQL ES

database index

row (one record) document

column type mapping

So "rebuilding an index" is like recreating a database.

Data format

ES uses JSON

{ "deal" : { "id" : 1 , "name" : "Proposal to TOYOTA" , "has_materials" : true } }

Enter fullscreen mode

Exit fullscreen mode

Writing search queries

Basic form

GET index name / _search { "query" : { conditions go here } }

Enter fullscreen mode

Exit fullscreen mode

query is the SQL WHERE clause.

I want an exact match (term)

In SQL:

WHERE has_materials = true

{ "query" : { "term" : { "deal.has_materials" : true } } }

Enter fullscreen mode

Exit fullscreen mode

I want to combine conditions with AND (= bool + filter)

In SQL:

WHERE has_materials = true AND invoice_id = 3

{ "query" : { "bool" : { "filter" : [ { "term" : { "deal.has_materials" : true } } , { "term" : { "deal.invoice.id" : 3 } } ] } } }

Enter fullscreen mode

Exit fullscreen mode

Listing…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.