elasticsearch-2.0,C#,Nest,elasticsearch 2.0" /> elasticsearch-2.0,C#,Nest,elasticsearch 2.0" />

C# 字段值因子的弹性嵌套等价

C# 字段值因子的弹性嵌套等价,c#,nest,elasticsearch-2.0,C#,Nest,elasticsearch 2.0,我需要修改一个使用.Nest构建SearchDescriptor的方法,以便为 具有合同价格(值为零)的项目的产品搜索结果 我捕获了查询的序列化版本,添加了“field\u value\u factor”以按所需顺序返回结果。我还没有决定如何在.Nest查询语句中实现这一点 有人能推荐如何修改.NEST客户端语句以生成相同的搜索描述符吗 多谢各位 下面是我们想要实现的查询,您将在底部看到字段\值\系数: { "from": 0, "size": 3000, "sort":

我需要修改一个使用.Nest构建SearchDescriptor的方法,以便为 具有合同价格(值为零)的项目的产品搜索结果

我捕获了查询的序列化版本,添加了“field\u value\u factor”以按所需顺序返回结果。我还没有决定如何在.Nest查询语句中实现这一点

有人能推荐如何修改.NEST客户端语句以生成相同的搜索描述符吗

多谢各位

下面是我们想要实现的查询,您将在底部看到字段\值\系数:

 {
      "from": 0,
  "size": 3000,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    },
    {
      "priceStatus": {
        "order": "asc"
      }
    },
    {
      "unitPrice": {
        "order": "asc"
      }
    }
  ],
  "aggs": {
    "PriceStatus": {
      "terms": {
        "field": "priceStatus",
        "size": 5
      }
    },
    "VendorName": {
      "terms": {
        "field": "vendorName",
        "size": 5
      }
    },
    "CatalogName": {
      "terms": {
        "field": "catalogName",
        "size": 5
      }
    },
    "ManufacturerName": {
      "terms": {
        "field": "manufacturerName",
        "size": 5
      }
    },
    "IsGreen": {
      "terms": {
        "field": "isGreen",
        "size": 5
      }
    },
    "IsValuePack": {
      "terms": {
        "field": "isValuePack",
        "size": 5
      }
    },
    "UnitOfMeasure": {
      "terms": {
        "field": "unitOfMeasure",
        "size": 5
      }
    },
    "Attributes": {
      "nested": {
        "path": "attributes"
      },
      "aggs": {
        "TheAttributeName": {
          "terms": {
            "field": "attributes.name",
            "size": 10
          },
          "aggs": {
            "TheAttributeValue": {
              "terms": {
                "field": "attributes.value",
                "size": 5
              }
            }
          }
        }
      }
    }
  },
  "query": {
    "function_score": { 
       "query": {
        "bool": {
          "should": [
            {
              "multi_match": {
                "type": "phrase",
                "query": "pen",
                "slop": 3,
                "boost": 16.0,
                "fields": [
                  "itemNumber*^4",
                  "shortDescription*^4",
                  "subCategory1Name*^1.5",
                  "subCategory2Name*^2.0",
                  "categoryName*^0.9",
                  "longDescription*^0.6",
                  "catalogName*^0.30",
                  "manufactureName*^0.20",
                  "vendorName*^0.15",
                  "upcCode*^0.10"
                ]
              }
            },
            {
              "multi_match": {
                "query": "pen",
                "boost": 15.0,
                "minimum_should_match": "75%",
                "fields": [
                  "itemNumber*^4",
                  "shortDescription*^4",
                  "subCategory1Name*^1.5",
                  "subCategory2Name*^2.0",
                  "categoryName*^0.9",
                  "longDescription*^0.6",
                  "catalogName*^0.30",
                  "manufactureName*^0.20",
                  "vendorName*^0.15",
                  "upcCode*^0.10"
                ]
              }
            },
            {
              "multi_match": {
                "query": "pen",
                "fuzziness": 1.0,
                "slop": 2,
                "minimum_should_match": "75%",
                "fields": [
                  "itemNumber*^4",
                  "shortDescription*^4",
                  "subCategory1Name*^1.5",
                  "subCategory2Name*^2.0",
                  "categoryName*^0.9",
                  "longDescription*^0.6",
                  "catalogName*^0.30",
                  "manufactureName*^0.20",
                  "vendorName*^0.15",
                  "upcCode*^0.10"
                ]
              }
            }
          ]
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "terms": {
                "catalogId": [
                  "fbb3dd2c-f81c-4ff3-bd5b-9c2cffc51540"
                ]
              }
            }
          ]
        }
      },
            "field_value_factor": {
                "field": "priceStatus",
                "factor": -1,
                "modifier": "none"
            }
        }
    }
}
以下是构建SearchDescriptor的当前方法:

private SearchDescriptor<SearchItem> BuildSearchDescriptor(
        string searchTerm,
        IList<Guid> catalogIds,
        int from,
        int size,
        string index,
        string preference,
        int attrSize,
        int valueSize,
        Dictionary<string, string[]> filterProps,
        Dictionary<string, string[]> filterAttrs,
        Guid? categoryId)
    {
        var searchDescriptor = new SearchDescriptor<SearchItem>()
            .From(from)
            .Size(size)
            .Query(q =>
                q.Filtered(fd => BuildFilterTerms(fd, filterProps, filterAttrs, catalogIds, categoryId)
                    .Query(iq => BuildQueryContainer(iq, searchTerm))
                )                    
            )
            .Index(index)
            .Preference(preference)
            .Aggregations(agg => BuildAggregationDescriptor(agg, attrSize, valueSize, catalogIds.Count))          
            .Sort(sort => sort.OnField("_score").Descending())
            .SortAscending(p=> p.PriceStatus)
            .SortAscending(p => p.UnitPrice);

        // Debug the raw string that will post to the ES servers i.e. use this in postman
        //var str = System.Text.Encoding.UTF8.GetString(client.Serializer.Serialize(searchDescriptor));

        return searchDescriptor;
    }
专用搜索描述符BuildSearchDescriptor(
字符串搜索项,
IList目录ID,
int from,
整数大小,
字符串索引,
字符串首选项,
int属性大小,
int-valueSize,
字典过滤程序,
字典过滤器,
Guid?类别ID)
{
var searchDescriptor=新的searchDescriptor()
.从(从)
.尺码(尺码)
.Query(q=>
q、 过滤(fd=>BuildFilterTerms(fd、filterProps、filterAttrs、CatalogID、categoryId)
.Query(iq=>BuildQueryContainer(iq,searchTerm))
)                    
)
.索引(索引)
.优惠(优惠)
.Aggregations(agg=>BuildAggregationDescriptor(agg、attrSize、valueSize、catalogIds.Count))
.Sort(Sort=>Sort.OnField(“\u score”).Descending())
.SortAscending(p=>p.PriceStatus)
.SortAscending(p=>p.单价);
//调试将发布到ES服务器的原始字符串,即在postman中使用此字符串
//var str=System.Text.Encoding.UTF8.GetString(client.Serializer.Serialize(searchDescriptor));
返回搜索描述符;
}

您的JSON查询无效<代码>字段\值\系数是
函数\分数
查询的函数。在Nest1.x中,这看起来像

var response = client.Search<Document>(x => x
    .Query(q => q
        .FunctionScore(fs => fs
            .Functions(fu => fu
                .FieldValueFactor(fvf => fvf
                    .Field(f => f.PriceStatus)
                    .Factor(-1)
                    .Modifier(FieldValueFactorModifier.None)
                )
            )
        )
    )
);

public class Document
{
    public string Title { get; set; }

    public int PriceStatus { get; set; }
}

您的JSON查询无效<代码>字段\值\系数是
函数\分数
查询的函数。在Nest1.x中,这看起来像

var response = client.Search<Document>(x => x
    .Query(q => q
        .FunctionScore(fs => fs
            .Functions(fu => fu
                .FieldValueFactor(fvf => fvf
                    .Field(f => f.PriceStatus)
                    .Factor(-1)
                    .Modifier(FieldValueFactorModifier.None)
                )
            )
        )
    )
);

public class Document
{
    public string Title { get; set; }

    public int PriceStatus { get; set; }
}
希望有帮助,希望有帮助。