Skip to content

Instantly share code, notes, and snippets.

SELECT * FROM mv_daily_sales_summary
WHERE seller_id = 'seller_123'
AND sale_date = '2024-01-30';
INSERT INTO
mv_daily_sales_summary
SELECT
o.tenant_id AS seller_id,
p.product_category,
o.order_date AS sale_date,
COUNT(*) AS total_orders,
SUM(o.total_amount) AS total_sales
FROM
orders o
PUT /movies/_mapping
{
"properties": {
"category": {
"type": "keyword"
}
}
}
from elasticsearch import Elasticsearch
# Connect to your Elasticsearch instance
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
# Index name and document ID for the example
index_name = 'your_index'
document_id = 'your_document_id'
# Specify the nested field and the updated value
from elasticsearch import Elasticsearch
# Connect to your Elasticsearch instance
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
# Index name and document ID you want to update
index_name = 'movies'
document_id = 'your_document_id'
# Define the Painless script for the update
from elasticsearch import Elasticsearch
# Connect to Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
# Index name and document ID
index_name = "your_index"
document_id = "1"
# Specify the fields to be updated
from elasticsearch import Elasticsearch
# Connect to Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
# Index name and document ID
index_name = "your_index"
document_id = "1"
# Retrieve the existing document
-
from elasticsearch import Elasticsearch
# Connect to your Elasticsearch instance
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
# Index name and document ID you want to update
index_name = 'movies'
document_id = 'your_document_id'
{
"name": "House of Cards",
"description": "Frank Underwood is a Democrat appointed as the Secretary of State. Along with his wife, he sets out on a quest to seek revenge from the people who betrayed him while successfully rising to supremacy.",
"genres": ["drama", "thriller"],
"views": 100,
}
SELECT p.title, p.content, c.text
FROM posts p
JOIN comments c ON p.post_id = c.post_id
WHERE p.post_id = 1;