Comments (8)
Hi @DR9885,
this repository contains the Elasticsearch client.
Enterprise Search and its App Search component is built on top of Elasticsearch, but is a completely dedicated product.
The App Search API is not fully compatible with the Elasticsearch API which means that it will never be supported by this client.
Creating a separate Enterprise Search client is on the roadmap for a while, but so far no progress has been made.
from elasticsearch-net.
Could you please show some code for option 2?
For this particular endpoint I don't see a reason why it would not work with the Elasticsearch client. The request and response is mostly just redirected to/from the underlying Elasticsearch instance.
You should be able to pass the full URI - including a path - to the ElasticsearchClientSettings or to the constructor of ElasticsearchClient without it being truncated.
from elasticsearch-net.
@flobernd
Client Version 7.17.5
Example Code
const string url = "https://fakehost.ent.westus2.azure.elastic-cloud.com/api/as/v1/engines/fake-engine/elasticsearch";
const string apiKey = "fake-key";
var connectionPool = new StaticConnectionPool(new [] { new Uri(url)});
var settings = new ConnectionSettings(connectionPool)
.ApiKeyAuthentication(new ApiKeyAuthenticationCredentials(apiKey));
var elasticClient = new ElasticClient(settings);
var searchResponse = elasticClient.Search<SearchOfferView>(s =>
s.Index("")
.TypedKeys(null)
.Query(q => q.MatchAll()));
Error
Unhandled exception. Elasticsearch.Net.UnsupportedProductException: The client noticed that the server is not Elasticsearch and we do not support this unknown product.
at Elasticsearch.Net.RequestPipeline.FirstPoolUsage(SemaphoreSlim semaphore)
at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
at Elasticsearch.Net.ElasticLowLevelClient.DoRequest[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
at Nest.ElasticClient.DoRequest[TRequest,TResponse](TRequest p, IRequestParameters parameters, Action`2 forceConfiguration)
at Nest.ElasticClient.Search[TDocument](ISearchRequest request)
at Nest.ElasticClient.Search[TDocument](Func`2 selector)
at Program.<Main>$(String[] args) in C:\Users\dr988\Documents\GitHub\TwoEightyCap.Service.Search\benchmark\TwoEightyCap.Service.Search.Benchmark\Program.cs:line 21
at Program.<Main>(String[] args)
from elasticsearch-net.
Was able to override the check.
var connectionPool = new StaticConnectionPool(new [] { new Uri(url)});
var prop = typeof(IConnectionPool).GetProperty("ProductCheckStatus");
prop.SetValue(connectionPool, ProductCheckStatus.ValidProduct, null);
But have new error if I do that
Invalid NEST response built from a unsuccessful (400) low level call on POST: /api/as/v1/engines/fake-engine-search-offer/elasticsearch/_search
# Audit trail of this API call:
- [1] PingSuccess: Node: https://fakehost-dev.ent.westus2.azure.elastic-cloud.com/api/as/v1/engines/fake-engine-search-offer/ Took: 00:00:01.7453793
- [2] BadResponse: Node: https://fakehost-dev.ent.westus2.azure.elastic-cloud.com/api/as/v1/engines/fake-engine-search-offer/ Took: 00:00:00.3943435
# OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 400 from: POST /api/as/v1/engines/fake-engine-search-offer/elasticsearch/_search
# Request:
{"query":{"match_all":{}}}
# Response:
It looks like these are request details being sent
Method: HEAD, RequestUri: 'https://fakehost-dev.ent.westus2.azure.elastic-cloud.com/api/as/v1/engines/fake-engine-search-offer/elasticsearch/', Version: 1.1, Content: <null>, Headers:
{
Accept: application/json
User-Agent: elasticsearch-net/7.17.5+34f1b0b42ae4e0227fb1ad9ebeb7ae3406a998ec
User-Agent: (Microsoft Windows 10.0.22631; .NET 8.0.0; Nest)
x-elastic-client-meta: es=7.17.5,net=8.0.0,t=7.17.5,a=0,so=8.0.0
Authorization: ApiKey fake-key
}
Manual curl does work
curl --request "POST" \
--url "https://fakehost-dev.ent.westus2.azure.elastic-cloud.com/api/as/v1/engines/fake-engine-search-offer/elasticsearch/_search" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer fake-key" \
--data '{"query": { "match_all": {} }}'
C# HttpClient Also Works
var client = new HttpClient(new HttpClientHandler(), false);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "fake-key");
using StringContent jsonContent = new(
JsonSerializer.Serialize(new
{
query = new { match_all = new {} }
}),
Encoding.UTF8,
"application/json");
var res = await client.PostAsync(new Uri("https://fakehost-dev.ent.westus2.azure.elastic-cloud.com/api/as/v1/engines/fake-engine-search-offer/elasticsearch/_search"), jsonContent, CancellationToken.None);
from elasticsearch-net.
@flobernd If I override the Authorization header it works, how can I change the header with nest client?
Works: Authorization: Bearer fake-key
Fails: Authorization: ApiKey fake-key
or can we get the App Engine to accept ApiKey as a type?
from elasticsearch-net.
@flobernd
Was able to override the transport authorization, but this is messy
var transportProperty = typeof(ElasticLowLevelClient).GetProperty("Transport", BindingFlags.Instance | BindingFlags.NonPublic);
var transport = (Transport<IConnectionSettingsValues>)transportProperty.GetValue(elasticClient.LowLevel);
transport.Settings.Headers.Add("Authorization", "Bearer fake-key");
from elasticsearch-net.
Full working hack
const string url = "https://fake-dev.ent.westus2.azure.elastic-cloud.com/api/as/v1/engines/tec-engine-search-offer/elasticsearch/";
const string apiKey = "fake-key";
var connectionPool = new StaticConnectionPool(new [] { new Uri(url)});
var settings = new ConnectionSettings(connectionPool)
.ApiKeyAuthentication(new ApiKeyAuthenticationCredentials(apiKey));
var elasticClient = new ElasticClient(settings);
// Hack: Validation
var prop = typeof(IConnectionPool).GetProperty("ProductCheckStatus");
prop.SetValue(connectionPool, ProductCheckStatus.ValidProduct, null);
// Hack: Fix Auth
var transportProperty = typeof(ElasticLowLevelClient).GetProperty("Transport", BindingFlags.Instance | BindingFlags.NonPublic);
var transport = (Transport<IConnectionSettingsValues>)transportProperty.GetValue(elasticClient.LowLevel);
transport.Settings.Headers.Add("Authorization", $"Bearer {apiKey}");
var searchResponse = elasticClient.Search<SearchOfferView>(s =>
s.Index("")
.TypedKeys(null)
.Query(q => q.MatchAll()));
from elasticsearch-net.
Thanks for providing a working hack! A similar workaround is probably possible with the 8.* client as well.
For now, I'm going to close this issue as it's related to the Enterprise Search / AppSearch product and not Elasticsearch 🙂
from elasticsearch-net.
Related Issues (20)
- QueryStringQuery fails when a single field is set for the Fields array HOT 1
- Nested ordering ignoring filter results
- Remove netcoreapp3.1 and net5.0 from TargetFrameworks and add net8.0 HOT 1
- Use Pull Request Labeler HOT 1
- Empty should collection is serialized improperly
- Support bucket_script HOT 1
- Bulk data failure HOT 2
- Unable to setup default similarity or more similarities with different name. HOT 2
- BoolQuery Must, Must-Not and Should type is not consistent HOT 4
- How to do BulkUpdates on a property in version 8.x? HOT 4
- Provide a typesafe and fluent way to return only a subset of data and to use script_fields HOT 7
- Custom SourceSerializer options not effective for response data HOT 3
- MultiSearch with multiple document types HOT 1
- Missing implicit operator for range queries HOT 1
- Discrepancy between Query types in Fields property HOT 1
- Exists property is missing from ExistsResponse and ExistsAliasResponse HOT 5
- Elastic.Transport.UnexpectedTransportException with Ingest.GetPipelineAsync HOT 3
- [BUG] RangeQuery API broken after upgrade from 8.12.1 to 8.13.1 HOT 6
- Total field is not filled anymore on the SearchResponse class
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-net.