Elasticsearch Nest Boost query

2019-08-07 16:02发布

问题:

Im trying to do a boosting query that reduces the score of documents where the field with name "type" and with the value "Press".

However NEST does not generate any values in the positive field in the generated json object:

  "query": {
    "boosting": {
      "positive": {},
      "negative": {
        "term": {
          "type": {
            "value": "Press"
          }
        }
      },
      "negative_boost": 0.2
    }
  }

Code Below:

var result = _elasticClient.Search<SearchablePage>(new SearchDescriptor<SearchablePage>()
                .Query(q => q
                    .Boosting(b => b
                        .NegativeBoost(0.2)
                        .Positive(p => p
                            .Filtered(fi => fi                        
                                .Filter(fq => fq
                                    .Term(t => t.Type, aggregation)
                                )
                                .Query(qq => qq
                                    .QueryString(qs => qs
                                        .Query(query)
                                        .OnFields(f => f.Name, f => f.Presentation, f => f.MainBody, f => f.SearchableBlocks.First().MainBody)
                                    )
                                )  
                            )
                        )
                        .Negative(n => n
                            .Term(f => f.OnField("type").Value("Press"))
                        )
                    )
                ));