Skip to content

Port Obvs.Monitoring.ElasticSearch from NEST to Elastic.Clients.Elasticsearch - #98

Closed
christopherread wants to merge 1 commit into
masterfrom
upgrade/elastic-client
Closed

christopherread wants to merge 1 commit into
masterfrom
upgrade/elastic-client

Conversation

@christopherread

Copy link
Copy Markdown
Owner

Fixes #77.

Changes

  • Package: NEST 7.17.5, which is deprecated and can't talk to Elasticsearch 9 servers, is replaced by Elastic.Clients.Elasticsearch 9.5.3. The new package still supports net472, netstandard2.0 and net10.0.
  • Saving counters: ElasticSearchMonitor uses the new client's IndexMany(documents, index), and logs errors from IsValidResponse and ElasticsearchServerError.

⚠️ Breaking changes for consumers

Before (NEST) After
ElasticSearchMonitorFactory(…, IElasticClient client) ElasticSearchMonitorFactory(…, ElasticsearchClient client)
ElasticSearchMonitor(…, IElasticClient client) ElasticSearchMonitor(…, ElasticsearchClient client)
ConnectToServer(IConnectionPool pool) (Elasticsearch.Net) ConnectToServer(NodePool pool) (Elastic.Transport)

ConnectToServer(string uri) is unchanged.

The new client supports Elasticsearch 8 and 9 servers, but not 7.

Stored data is unchanged

Counters still go to <prefix>-yyyy.MM.dd with camelCase fields (counterName, instanceName, direction, timeStamp, …) and ISO-8601 dates, so existing indexes and dashboards keep working. The index name is now in the request URL (/<index>/_bulk) instead of in each action line, which is equivalent.

Tests

The new client has no interface like IElasticClient to fake. So the tests run the real ElasticsearchClient against Elastic's InMemoryRequestInvoker, which answers like a real server, and assert on the _bulk requests it actually sends.

  • Existing behaviour, same assertions:
    • nothing is saved without messages;
    • one bulk request after sends or receives;
    • with per-type counters, it contains 2 documents.
  • New test, ShouldIndexCountersInDailyIndexWithCamelCaseFields: pins the daily index name and the camelCase fields. It didn't exist before, so it never ran against NEST; the document format was compared against NEST's camelCase defaults by hand.

Testing gotcha: the in-memory transport's default response lacks the x-elastic-product header. The client then throws UnsupportedProductException, which the monitor catches and logs, so tests can pass while only exercising the error path. The test setup returns that header.

All 125 unit tests pass, and the solution builds for net472, netstandard2.0 and net10.0 with no new warnings. Not run against a real Elasticsearch server: there's no Docker here and no Elasticsearch in CI.

🤖 Generated with Claude Code

…icsearch

NEST is deprecated and can't talk to Elasticsearch 9. Use
Elastic.Clients.Elasticsearch 9.5.3: ElasticsearchClient replaces
IElasticClient and NodePool replaces IConnectionPool in the public API.
Counters are still bulk-indexed into <prefix>-yyyy.MM.dd with camelCase
fields, so existing indexes keep working.

The tests now run the real client against Elastic's in-memory transport
and assert on the bulk requests it sends, as the new client has no
interface to fake.

Fixes #77

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@christopherread

Copy link
Copy Markdown
Owner Author

Combined into #104, which includes this change as its own commit.

christopherread added a commit that referenced this pull request Oct 25, 2026
…h and NATS.Net ports, Kafka subscribe fix (#104)

Fixes #74, fixes #76, fixes #77, fixes #78, fixes #79, fixes #103.

Combines #82, #83, #96, #98 and #99, plus the Kafka subscribe fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@christopherread
christopherread deleted the upgrade/elastic-client branch October 25, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate Obvs.Monitoring.ElasticSearch from NEST to Elastic.Clients.Elasticsearch

1 participant