Code Monkey home page Code Monkey logo

Comments (4)

flobernd avatar flobernd commented on July 17, 2024 1

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.

flobernd avatar flobernd commented on July 17, 2024

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.

giannik avatar giannik commented on July 17, 2024

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.

flobernd avatar flobernd commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.