Comments (4)
Going to close this issue for now, but please feel free to open a new one, if you have additional questions, etc.
from elasticsearch-net.
Hi @giannik,
I think this might be the same case that I tried to explain to you a few days ago in this comment.
Manual (De-)serialization of the data structures is an unsupported use-case.
[...] certain types only implement either serialization OR deserialization
For the majority of cases, Request
types only implement serialization
(because they are never deserialized in the client).
Could you please check, if the same query as well causes an error, if you build it by using e.g. the fluent API? If that's the case I will investigate further, but otherwise this best thing I can recommend to you is:
Usually we suggest using your own custom CLR types and copy over / assign the values from the Elasticsearch types.
from elasticsearch-net.
i can confirm that using the typed client for knn works :
var floatList = new List<float> { 0.0185484141f, -0.000538613356f };
var searchResponse1 = await _elasticClient.SearchAsync<Dictionary<string, object>>(s =>
s.Index(_indexPrefix + indexName)
.Knn(qd =>
{
qd.k(2)
.NumCandidates(100)
.Field("ContentItem_Vector.vector")
.QueryVector(floatList);
}));
but i was looking for a generic mechanism to just pass the json i write in the dev console to the c# client and execute it . it works for query dsl type queries but not for knn.
so basically given my current code for the generic mechanism is this :
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(query));
var deserializedSearchRequest = _elasticClient.RequestResponseSerializer.Deserialize<SearchRequest>(stream);
var searchRequest = new SearchRequest(_indexPrefix + indexName)
{
// Knn = deserializedSearchRequest.Knn,
Query = deserializedSearchRequest.Query,
From = deserializedSearchRequest.From,
Size = deserializedSearchRequest.Size,
Fields = deserializedSearchRequest.Fields,
Sort = deserializedSearchRequest.Sort,
Source = deserializedSearchRequest.Source,
};
var searchResponse = await _elasticClient.SearchAsync<Dictionary<string, object>>(searchRequest);
the sugestion is i should skip this part :
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(query));
var deserializedSearchRequest = _elasticClient.RequestResponseSerializer.Deserialize<SearchRequest>(stream);
and rather deserialize to my own objects and then pass in the values needed the the client :
var searchRequest = new SearchRequest(_indexPrefix + indexName)
{
Knn = MYdeserializedSearchRequest.Knn,
Query = MYdeserializedSearchRequest.Query,
From = MYdeserializedSearchRequest.From,
Size = MYdeserializedSearchRequest.Size,
Fields = MYdeserializedSearchRequest.Fields,
Sort = MYdeserializedSearchRequest.Sort,
Source = MYdeserializedSearchRequest.Source,
};
var searchResponse = await _elasticClient.SearchAsync<Dictionary<string, object>>(searchRequest);
Correct ?
from elasticsearch-net.
Hi @giannik, yes that's essentially what we suggest in these cases 🙂
I understand that a full round-trippable (de-)serialization would provide a convenient way of executing queries that are stored as JSON, but at the moment there are not plans to support this.
i was looking for a generic mechanism to just pass the json i write in the dev console to the c# client and execute it . it works for query dsl type queries but not for knn.
The query-dsl types are round-trippable, because they are as well returned by some APIs, which mans we need both serialization- and deserialization support for them in the client.
Maybe reflection could be used to implement a completely generic way of executing queries for your console app use-case.
from elasticsearch-net.
Related Issues (20)
- Fluent API for composite aggregation sources
- IndexSettingsConverter tries to deserialize routing_path as collection of string even if there is a string in raw JSON response HOT 1
- ESQL Arrow support
- Implement Connectors API
- Add back TermsRangeQuery in the Elasticsearch .Net Client HOT 1
- error in elastic client when trying to get the mappings HOT 5
- Improve usability of `FiltersAggregation`
- Adding document to Elastic with Client.IndexAsync doesn't await result; also ambigious function parameters HOT 7
- ElasticsearchClient.Indicies.GetAsync throws UnexpectedTransportException
- IndexSettings NumberOfShards and NumberOfReplicas are objects, not int/long as expected HOT 4
- Being more careful with releases HOT 1
- upsert operation and refresh set to 3s HOT 1
- Removing an single alias for indices throws 404 index not found HOT 4
- Using Must overload that accepts collection of Query objects doesn't work HOT 3
- KNNQuery Inner Hits HOT 3
- Allow use of Elasticsearch icon in .NET Aspire components? HOT 1
- Support OpentTelemetry Metrics HOT 2
- GetRepositoryResponse is unusable as it does not expose the actual response data
- MultiGetRequest does not serialize request parameters for SourceConfigParam properly
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.