NEST与JSON语法对照 一 match与multi_match

时间:2025-04-05 22:37:13
  {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "一二三",
"fields": ["title","summary"]
}
},
{"match": {"userId": {"query": "123456"}}
}
]
}
}
}

  C#

search.Query(
q => q.Bool(
b => b.Must(
m => m.MultiMatch(
l => l.Query("一二三").OnFields(new[] {"title","summary"})
),
m => m.Match(t => t.OnField(o => o.UserId).Query("123456"))
)
)
)

当然如果是Json

{"match": {"userId": {"query": "123456"}} 
也可以表述为
{"match": {"userId":"123456"}

其中OnField/OnFields可以使用lamdba 表达式来选择属性,也可以使用字符串