Tues November 14th 2023 Notes - Hsanokklis/2023-2024-Tech-journal GitHub Wiki
Elasticsearch
- open source
- built with java
- NoSQL database (not using structured data, not tabular)
- data is stored in documents
- data has relationships through the indexes and through the queries (show me all the bills from California - that's a relationship)
SQL
You had data on customer information which your sales team queried regularly
Each row in each table is a single customer, and each column has the following fixed attributes
NoSQL
We can store the same data in an unstructued format
Combine both the basic information and the customer information in one JSON document instead of a bunch of tables
Basic Elasticsearch Concepts
Index
- Indices are logical partitions of documents and can be compared to a database
- Indices hold documents that are unique to each index
- indices are identifies by lowercase
documents
- JSON objects that are stored within an Elasticsearch index and are considered the base unit of storage (JSON is more common in Elasticsearch then XML)
Shards
- Index size is a common cause of Elasticsearch crashes
- there is no limit to how many documents you can store on each index
- Each shard contains different documents split across multiple nodes (servers) in a cluster.
REST API
- allows you to integrate, manage and query the indexed data in countless different ways
- Any HTTP client HTTP can be used - and Kibana comes with a built-on tool called Console which can be used for this purpose
API Categories
- Document API
- Search API
- Indices API
- Cluster API
Elasticsearch Queries
Elasticsearch supports some different ways to query the data
-
URL Search
- Sending search queries through a URL with a GET request
- Great for simple queries
- use
curl
and put the entire search in the URL
-
Request Body Search Using Query DSL
- Uses the body of a HTTP request (POST, PUT)
- Query actually formatted in JSON - and can allow for sophisticated "nesting"
URI Search
Search across all indexes for the string "champ"
curl -XGET 'localhost':9200/_search?q=champ'
get the name filed that is equal to champ
curl -XGET 'localhost':9200/_search?q=name:champ'
Whatever comes after the question mark is a parameter
Query DSL
- used to create more complex queries
curl localhost:9200/ - d
- -d is a post, says that's it in the body and not URL
Elasticsearch Query types
- Geo queries
- More like this queries