Comments (7)
Hi @insulationman,
thanks for requesting this feature. The decay functions will be implemented soon. They require some special handling to get generated correctly.
from elasticsearch-net.
Hi @jasielmacedo,
but intercepting the JSON or executing a complete JSON request? why use this library anyway?
This library supports more than 450 endpoints and nearly 3000 types. I spent the past 6+ months continuing the good work of Martijn and Steve to get the code generator to a point where it finally supports 95%+ of the overall available Elasticsearch functionality. For me, these are at least 450 reasons to use the library, even if I would have to manually craft one JSON request myself - but that's of course just my personal opinion.
I think suggesting to not use this library with a product that was developed using this version 8 of the library is insane.
I think we misunderstood here. I'm strongly suggesting to use the library! You can use the regular client for everything besides the query that uses decay functions. For this particular case, you can fall-back to the low-level client (which still saves you from having to build the complete transport level layer yourself). The low level client is exposed by the regular client:
https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/migration-guide.html#_workarounds_for_missing_features
I know that the above workaround is not perfect. At the same time, please note, that a lot has been added to the library in the last weeks and a lot of bugs have been fixed and usability problems have been addressed. I'm sorry, that the decay functions were not part of this yet, but they are on my todo list and I excpect then to be available within weeks.
What I'm asking is just a possibility of creating my own FunctionScore so I don't need to rewrite the whole code just to add one additional feature
I can give you another hacky alternative. Using reflection you could access the internal
constructor of FunctionScore
to manually create an instance with a custom variant:
internal FunctionScore(string variantName, object variant)
For variantName
use one of linear
, gauss
or exp
.
For variant
, create your own typed function score class or use JSON for this part like this:
var gauss = """
{
"timestamp": {
"scale": "4w"
}
}
"""
var variant = new RawJsonString(gauss);
The RawJsonString
class is a special struct that serializes the contained string as raw json (without quotes).
from elasticsearch-net.
@flobernd Thanks. Yeah, I was wrong. It wasn't clear in the beginning but reading the code of the library I figured out.
I ended up creating a similar solution using the Transport class you suggested, let me share here so if someone has the same issue they could adapt for their case as well while the final solution is not ready:
For the request I just updated the way I execute the query. I just created a delegate so I can intercept the json.
var json = _client.RequestResponseSerializer.SerializeToString(searchRequestDescriptor);
json = AddGaussFunction(json);
var queryParameters = new DefaultRequestParameters();
// I added this because I'm using aggregations and suggester
queryParameters.SetQueryString("typed_keys", true);
var response = await _client.Transport.RequestAsync<SearchResponse<T>>(Elastic.Transport.HttpMethod.POST, $"/{indexName}/_search", PostData.String(json), queryParameters).ConfigureAwait(false);
if (!response.IsValidResponse)
{
/// throw error or do whatever you want to do with the error
}
return response;
So My case the function score
was being added right after the first query so it was simple to update the json, but with a simple tweak it can be used anywhere
void AddGaussFunction(string jsonString, int scale, int offset)
{
try
{
JsonObject jsonObject = JsonNode.Parse(jsonString).AsObject();
if (jsonObject["query"]?["function_score"]?["functions"] is JsonArray functionsArray)
{
var now = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds();
var gaussFunction = JsonNode.Parse($@"
{{
""gauss"": {{
"""": {{
""origin"": ""{now}"",
""scale"": ""{scale}"",
""offset"": ""{offset}"",
""decay"": 0.7
}}
}},
""weight"": 1.2,
""filter"": {{
""term"": {{
""customfield"": ""CustomType""
}}
}}
}}
").AsObject();
functionsArray.Add(gaussFunction);
return jsonObject.ToJsonString(new JsonSerializerOptions { WriteIndented = true });
}
else
{
return jsonString;
}
}
catch (JsonException e)
{
throw new InvalidOperationException("Error parsing JSON.", e);
}
}
from elasticsearch-net.
@flobernd So I think it's better to at least give us options to create our own solution for that. Like I'm stuck trying to think in a workaround to use gauss function and even the Serializer function you put internal ctor
So I can't create my own descriptor for example locally
It's been a year #7428
You don't have time to create this function but you don't allow anyone else to at least try to create their own solution for that locally? This version 8 is incomplete and you have to give devs options to keep using it.
from elasticsearch-net.
From the other post:
you could consider dropping to the Transport layer (available from the client instance), where you can send a complete request as JSON and handle the JSON response
An example of how to use the low level transport can be found in the migration guide.
from elasticsearch-net.
@flobernd thanks for the suggestion but intercepting the JSON or executing a complete JSON request? why use this library anyway?
I appreciate you came here to answer this, but I think suggesting to not use this library with a product that was developed using this version 8 of the library is insane.
What I'm asking is just a possibility of creating my own FunctionScore so I don't need to rewrite the whole code just to add one additional feature
from elasticsearch-net.
Related to: elastic/elasticsearch-specification#2545
from elasticsearch-net.
Related Issues (20)
- ExtendedBounds missing from DateHistogramAggregationDescriptor<TDocument> HOT 1
- Unable to perform knn query [knn] unknown field [k HOT 7
- Dictionary exception in BucketsPathConverter HOT 5
- Elasticsearch.Net.UnexpectedElasticsearchClientException: Failed to serialize anonymous type when writting to NLog HOT 3
- Missing && operator between aggregations HOT 5
- Another Elastic.Transport.UnexpectedTransportException with Ingest.GetPipelineAsync HOT 2
- Reintroduce convenience where appropriate HOT 4
- Default index is not used in query with 8.13.8 client HOT 5
- Missing Public Constructor on Type Elastic.Clients.Elasticsearch.Fields HOT 2
- SumAggregation missing ctor HOT 7
- BulkAll does not honor [JsonIgnore] attribute HOT 2
- GeoPoint Serialization Helper HOT 3
- MultiGetAsync does not infer default mapping for index HOT 4
- Support for (alternative for) GeoShapeQuery HOT 2
- After/AfterKey dictionary types in Composite Aggregation/Aggregate HOT 1
- 8.13.10 lacks UpdateMany<TSource, TPartialDocument>
- Latest MINOR package version does not support .Net 6 anymore. HOT 3
- Elastic.Transport.UnexpectedTransportException with Indices.GetAsync HOT 4
- Indices.ExistsAsync throw exception due to ICU field HOT 6
- Queries are no longer derive from SearchQuery HOT 4
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.