Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

c# - ElasticSearch NEST - FieldValueFactorFunction score function outputting invalid json query

Let me preface this to say I'm newer to ElasticSearch and NEST, and may be doing something wrong. This is using NEST 7.6.2.
I'm following the documentation to create a field_value_factor score function containing a filter and weight using object initializer syntax, i.e.:

new FieldValueFactorFunction
{
    Field = "foo",
    Modifier = FieldValueFactorModifier.Log1P,
    Missing = 1,
    Filter = new MatchQuery
    {
        Field = "bar",
        Query = "1"
    },
    Weight = .2
}

However, at runtime it appears to output an invalid json format in the query itself:

{
    "filter": {
        "match": {
            "bar": {
                "query": "1"
            }
        }
    },
    "field_value_factor": {
        "field": "foo",
        "missing": 1.0,
        "modifier": "log1p",
        "filter": {
            "match": {
                "bar": {
                    "query": "1"
                }
            }
        },
        "weight": 0.2
    },
    "weight": 0.2
}

Which fails with the error field_value_factor query does not support [value]. I do know the valid function syntax I'm trying to emulate is the following:

{
    "filter": {
        "match": {
            "bar": {
                "query": "1"
            }
        }
    },
    "field_value_factor": {
        "field": "foo",
        "missing": 1.0,
        "modifier": "log1p"
    },
    "weight": 0.2
}

Is this a bug in NEST/Elasticsearch.net? Is my syntax incorrect? Is there an alternate way to do what I'm trying to do?

question from:https://stackoverflow.com/questions/66051008/elasticsearch-nest-fieldvaluefactorfunction-score-function-outputting-invalid

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This was apparently an issue in the version of NEST I was using. Updating the nuget package resolved it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...