Movatterモバイル変換


[0]ホーム

URL:


Loading

Elasticsearch Python DSL

Elasticsearch DSL is a module of the official Python client that aims to help with writing and running queries against Elasticsearch in a more convenient and idiomatic way. It stays close to the Elasticsearch JSON DSL, mirroring its terminology and structure. It exposes the whole range of the DSL from Python either directly using defined classes or a queryset-like expressions. Here is an example:

from elasticsearch.dsl import Searchfrom elasticsearch.dsl.query import Match, Terms = Search(index="my-index") \    .query(Match("title", "python")) \    .filter(Term("category", "search")) \    .exclude(Match("description", "beta"))for hit in s:    print(hit.title)

Or with asynchronous Python:

from elasticsearch.dsl import AsyncSearchfrom elasticsearch.dsl.query import Match, Termasync def run_query():    s = AsyncSearch(index="my-index") \        .query(Match("title", "python")) \        .filter(Term("category", "search")) \        .exclude(Match("description", "beta"))    async for hit in s:        print(hit.title)

It also provides an optional wrapper for working with documents as Python objects: defining mappings, retrieving and saving documents, wrapping the document data in user-defined classes.

To use the other Elasticsearch APIs (eg. cluster health) just use the regular client.

Welcome to the docs for thelatest Elastic product versions, including Elastic Stack 9.0 and Elastic Cloud Serverless.To view previous versions, go toelastic.co/guide.


[8]ページ先頭

©2009-2025 Movatter.jp