如何在 nest 1.7 中编写 existsQuery
how to write existsQuery in nest 1.7
我正在使用 nest 1.7,我需要编写此查询:
GET _search
{
"from": 0,
"size": 3,
"query": {
"bool": {
"must": [
{
"constant_score": {
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"exists": {
"field": "Collaborateurs"
}
},
{
"exists": {
"field": "Collaborateurs.Nom"
}
},
{
"exists": {
"field": "Collaborateurs.Fonction"
}
},
{
"exists": {
"field": "Collaborateurs.TagVisuel"
}
},
{
"exists": {
"field": "siAnnuaire"
}
},
{
"term": {
"siAnnuaire": {
"value": true
}
}
},
{
"exists": {
"field": "TagPhoto"
}
},
{
"range": {
"NbAnnonce": {
"gt": 0
}
}
},
{
"geo_distance": {
"distance": "10.0km",
"AgenceLocation": {
"lat": 48.8523513700019,
"lon": 2.35127712591128
}
}
}
]
}
}
]
}
}
}
},
{
"function_score": {
"functions": [
{
"random_score": {
"seed": 69937385
}
}
]
}
}
]
}
}
}
使用流畅的 API,方法调用几乎遵循查询 DSL 的结构 json
var response = client.Search<Document>(x => x
.From(0)
.Size(3)
.Query(q => q
.Bool(b => b
.Must(m => m
.ConstantScore(cs => cs
.Filter(csf => csf
.Bool(cb => cb
.Must(
cm => cm.Exists(p => p.Collaborateurs),
cm => cm.Exists(p => p.Collaborateurs.Nom),
cm => cm.Exists(p => p.Collaborateurs.Fonction)
// etc, etc for the other queries
)
)
)
), m => m
.FunctionScore(fs => fs
.Functions(fu => fu
.RandomScore(69937385)
)
)
)
)
)
);
产生
{
"from": 0,
"size": 3,
"query": {
"bool": {
"must": [
{
"constant_score": {
"filter": {
"bool": {
"must": [
{
"exists": {
"field": "collaborateurs"
}
},
{
"exists": {
"field": "collaborateurs.nom"
}
},
{
"exists": {
"field": "collaborateurs.fonction"
}
}
]
}
}
}
},
{
"function_score": {
"functions": [
{
"random_score": {
"seed": 69937385
}
}
]
}
}
]
}
}
}
字段名称默认采用驼峰式大小写,但您可以使用 ConnectionSettings
上的 .SetDefaultPropertyNameInferrer(Func<string, string>)
更改此行为。
我正在使用 nest 1.7,我需要编写此查询:
GET _search
{
"from": 0,
"size": 3,
"query": {
"bool": {
"must": [
{
"constant_score": {
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"exists": {
"field": "Collaborateurs"
}
},
{
"exists": {
"field": "Collaborateurs.Nom"
}
},
{
"exists": {
"field": "Collaborateurs.Fonction"
}
},
{
"exists": {
"field": "Collaborateurs.TagVisuel"
}
},
{
"exists": {
"field": "siAnnuaire"
}
},
{
"term": {
"siAnnuaire": {
"value": true
}
}
},
{
"exists": {
"field": "TagPhoto"
}
},
{
"range": {
"NbAnnonce": {
"gt": 0
}
}
},
{
"geo_distance": {
"distance": "10.0km",
"AgenceLocation": {
"lat": 48.8523513700019,
"lon": 2.35127712591128
}
}
}
]
}
}
]
}
}
}
},
{
"function_score": {
"functions": [
{
"random_score": {
"seed": 69937385
}
}
]
}
}
]
}
}
}
使用流畅的 API,方法调用几乎遵循查询 DSL 的结构 json
var response = client.Search<Document>(x => x
.From(0)
.Size(3)
.Query(q => q
.Bool(b => b
.Must(m => m
.ConstantScore(cs => cs
.Filter(csf => csf
.Bool(cb => cb
.Must(
cm => cm.Exists(p => p.Collaborateurs),
cm => cm.Exists(p => p.Collaborateurs.Nom),
cm => cm.Exists(p => p.Collaborateurs.Fonction)
// etc, etc for the other queries
)
)
)
), m => m
.FunctionScore(fs => fs
.Functions(fu => fu
.RandomScore(69937385)
)
)
)
)
)
);
产生
{
"from": 0,
"size": 3,
"query": {
"bool": {
"must": [
{
"constant_score": {
"filter": {
"bool": {
"must": [
{
"exists": {
"field": "collaborateurs"
}
},
{
"exists": {
"field": "collaborateurs.nom"
}
},
{
"exists": {
"field": "collaborateurs.fonction"
}
}
]
}
}
}
},
{
"function_score": {
"functions": [
{
"random_score": {
"seed": 69937385
}
}
]
}
}
]
}
}
}
字段名称默认采用驼峰式大小写,但您可以使用 ConnectionSettings
上的 .SetDefaultPropertyNameInferrer(Func<string, string>)
更改此行为。