Skip to content

How to create a functionscore in version 8 of the driver as we did with NEST7? #8508

@alkampfergit

Description

@alkampfergit

I have the following code that is perfectly working with NEST 7, now I need to translate to the version 8 of the driver, but I was unable to find documentation. Can someone point me to the right direction?

  string scale = Scale;
  if (Scale.EndsWith('M'))
  {
      var days = Convert.ToInt32(Scale[..^1]) * 30;
      scale = $"{days}d";
  }
  return new Nest.LinearDateDecayFunction
  {
      Field = OmniSearchItem.GetDateTimeDynamicPropertyName(BoostPropertyName),
      Weight = Weight,
      Origin = Nest.DateMath.Now,
      Decay = Decay,
      Scale = scale
  };

Actually I've tried this code but I was unable to set the weight parameter.

      var ddf = new Elastic.Clients.Elasticsearch.QueryDsl.DateDecayFunction();
      ddf.Field = OmniSearchItem.GetDateTimeDynamicPropertyName(BoostPropertyName);
      ddf.Placement = new Elastic.Clients.Elasticsearch.QueryDsl.DecayPlacement<Elastic.Clients.Elasticsearch.DateMath, Elastic.Clients.Elasticsearch.Duration>();
      ddf.Placement.Origin = Elastic.Clients.Elasticsearch.DateMath.Now;
      ddf.Placement.Scale = scale;
      ddf.Placement.Decay = Decay;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions