将原始弹性搜索查询转换为 NEST 查询
Translate raw elastic search query into NEST query
我想知道,是否有人可以将以下原始弹性搜索查询翻译成 NEST?谢谢!
var json = @"
{
""from"": 0,
""size"": 50,
""query"": {
""constant_score"": {
""filter"": {
""bool"": {
""must"": [
{
""range"": {
""attachment.content_length"": {
""gt"": 0,
""lte"": 500
}
}
},
{
""term"": {
""ext"": {
""value"": ""pdf""
}
}
},
{
""term"": {
""check"": {
""value"": false
}
}
}
]
}
}
}
}
}
";
var searchResponse = await client.SearchAsync<object>(s => s
.From(0)
.Size(50)
.Query(q => q.ConstantScore(cs => cs
.Filter(f => f.Bool(b => b.Must(
m => m.Range(r => r.Field("attachment.content_length").GreaterThan(0).LessThanOrEquals(500)),
m => m.Term(t => t.Field("ext").Value("pdf")),
m => m.Term(t => t.Field("check").Value(false))
))))));
或稍微更强类型的版本
var searchResponse = await client.SearchAsync<Document>(s => s
.From(0)
.Size(50)
.Query(q => q.ConstantScore(cs => cs
.Filter(f => f.Bool(b => b.Must(
m => m.Range(r => r.Field(field => field.Attachment.ContentLength).GreaterThan(0).LessThanOrEquals(500)),
m => m.Term(t => t.Field(field => field.Ext).Value("pdf")),
m => m.Term(t => t.Field(field => field.Check).Value(false))
))))));
public class Document
{
public int Id { get; set; }
public Nest.Attachment Attachment { get; set; }
public string Ext { get; set; }
public bool Check { get; set; }
}
都产生以下查询
{
"from": 0,
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [{
"range": {
"attachment.content_length": {
"gt": 0.0,
"lte": 500.0
}
}
}, {
"term": {
"ext": {
"value": "pdf"
}
}
}, {
"term": {
"check": {
"value": false
}
}
}
]
}
}
}
},
"size": 50
}
希望对您有所帮助。
我想知道,是否有人可以将以下原始弹性搜索查询翻译成 NEST?谢谢!
var json = @"
{
""from"": 0,
""size"": 50,
""query"": {
""constant_score"": {
""filter"": {
""bool"": {
""must"": [
{
""range"": {
""attachment.content_length"": {
""gt"": 0,
""lte"": 500
}
}
},
{
""term"": {
""ext"": {
""value"": ""pdf""
}
}
},
{
""term"": {
""check"": {
""value"": false
}
}
}
]
}
}
}
}
}
";
var searchResponse = await client.SearchAsync<object>(s => s
.From(0)
.Size(50)
.Query(q => q.ConstantScore(cs => cs
.Filter(f => f.Bool(b => b.Must(
m => m.Range(r => r.Field("attachment.content_length").GreaterThan(0).LessThanOrEquals(500)),
m => m.Term(t => t.Field("ext").Value("pdf")),
m => m.Term(t => t.Field("check").Value(false))
))))));
或稍微更强类型的版本
var searchResponse = await client.SearchAsync<Document>(s => s
.From(0)
.Size(50)
.Query(q => q.ConstantScore(cs => cs
.Filter(f => f.Bool(b => b.Must(
m => m.Range(r => r.Field(field => field.Attachment.ContentLength).GreaterThan(0).LessThanOrEquals(500)),
m => m.Term(t => t.Field(field => field.Ext).Value("pdf")),
m => m.Term(t => t.Field(field => field.Check).Value(false))
))))));
public class Document
{
public int Id { get; set; }
public Nest.Attachment Attachment { get; set; }
public string Ext { get; set; }
public bool Check { get; set; }
}
都产生以下查询
{
"from": 0,
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [{
"range": {
"attachment.content_length": {
"gt": 0.0,
"lte": 500.0
}
}
}, {
"term": {
"ext": {
"value": "pdf"
}
}
}, {
"term": {
"check": {
"value": false
}
}
}
]
}
}
}
},
"size": 50
}
希望对您有所帮助。