- Elastic Cloud Serverless
- Elasticsearch
- Elastic Observability
- Get started
- Observability overview
- Elastic Observability Serverless billing dimensions
- Create an Observability project
- Quickstart: Monitor hosts with Elastic Agent
- Quickstart: Monitor your Kubernetes cluster with Elastic Agent
- Quickstart: Monitor hosts with OpenTelemetry
- Quickstart: Unified Kubernetes Observability with Elastic Distributions of OpenTelemetry (EDOT)
- Quickstart: Collect data with AWS Firehose
- Get started with dashboards
- Applications and services
- Application performance monitoring (APM)
- Get started with traces and APM
- Learn about data types
- Collect application data
- View and analyze data
- Act on data
- Use APM securely
- Reduce storage
- Managed intake service event API
- Troubleshooting
- Synthetic monitoring
- Get started
- Scripting browser monitors
- Configure lightweight monitors
- Manage monitors
- Work with params and secrets
- Analyze monitor data
- Monitor resources on private networks
- Use the CLI
- Configure a Synthetics project
- Multifactor Authentication for browser monitors
- Configure Synthetics settings
- Grant users access to secured resources
- Manage data retention
- Scale and architect a deployment
- Synthetics Encryption and Security
- Troubleshooting
- Application performance monitoring (APM)
- Infrastructure and hosts
- Logs
- Inventory
- Incident management
- Data set quality
- Observability AI Assistant
- Machine learning
- Reference
- Get started
- Elastic Security
- Elastic Security overview
- Security billing dimensions
- Create a Security project
- Elastic Security requirements
- Elastic Security UI
- AI for Security
- Ingest data
- Configure endpoint protection with Elastic Defend
- Manage Elastic Defend
- Endpoints
- Policies
- Trusted applications
- Event filters
- Host isolation exceptions
- Blocklist
- Optimize Elastic Defend
- Event capture and Elastic Defend
- Endpoint protection rules
- Identify antivirus software on your hosts
- Allowlist Elastic Endpoint in third-party antivirus apps
- Elastic Endpoint self-protection features
- Elastic Endpoint command reference
- Endpoint response actions
- Cloud Security
- Explore your data
- Dashboards
- Detection engine overview
- Rules
- Alerts
- Advanced Entity Analytics
- Investigation tools
- Asset management
- Manage settings
- Troubleshooting
- Manage your project
- Changelog
Get started with the serverless .NET client
editGet started with the serverless .NET client
editThis client is for use with Elasticsearch Serverless only. See also the Elasticsearch clients.
This page guides you through the installation process of the .NET client for Elasticsearch Serverless, shows you how to initialize the client, and how to perform basic Elasticsearch operations with it.
Requirements
edit- .NET Core, .NET 5+ or .NET Framework (4.6.1 and higher).
Installation
editYou can install the .NET client with the following command:
dotnet add package Elastic.Clients.Elasticsearch.Serverless
Initialize the client
editInitialize the client using your API key and Elasticsearch endpoint:
var client = new ElasticsearchClient("<CLOUD_ID>", new ApiKey("<API_KEY>"));
To get API keys for the Elasticsearch endpoint for a project, see Get started.
Using the API
editAfter you’ve initialized the client, you can create an index and start ingesting documents.
Creating an index and ingesting documents
editThe following is an example of creating a my_index
index:
var response = await client.Indices.CreateAsync("my_index");
This is a simple way of indexing a document into my_index
:
var doc = new MyDoc { Id = 1, User = "xyz_user", Message = "Trying out the client, so far so good?" }; var response = await client.IndexAsync(doc, "my_index");
Getting documents
editYou can get documents by using the following code:
var response = await client.GetAsync<MyDoc>(id, idx => idx.Index("my_index")); if (response.IsValidResponse) { var doc = response.Source; }
Searching
editThis is how you can create a single match query with the .NET client:
var response = await client.SearchAsync<MyDoc>(s => s .Index("my_index") .From(0) .Size(10) .Query(q => q .Term(t => t.User, "flobernd") ) ); if (response.IsValidResponse) { var doc = response.Documents.FirstOrDefault(); }
Updating a document
editThis is how you can update a document, for example to add a new field:
doc.Message = "This is a new message"; var response = await client.UpdateAsync<MyDoc, MyDoc>("my_index", 1, u => u .Doc(doc));
Deleting a document
editvar response = await client.DeleteAsync("my_index", 1);
Deleting an index
editvar response = await client.Indices.DeleteAsync("my_index");
On this page