如何在 Elasticsearch 中使用 .nest NEST 來形成如下查詢: select * from tbl where tbl.id in [1, 3, 10] ?或者換句話說,如何形成一個查詢來查找其 id 存在于某個串列中的所有記錄,例如 [1, 3, 10]?
uj5u.com熱心網友回復:
您可以使用下面的 Elasticsarch 查詢來搜索檔案_id欄位。
POST index1/_search
{
"query": {
"ids": {
"values": ["1","2","3"]
}
}
}
下面是等效的 .Net 代碼。
var ids = new long[] { 1, 2, 3 };
var multiGetResponse = client.Search<MyDocument>(s => s
.Index("index1")
.Query(q => q
.Ids(i => i
.Values(ids)
)
)
);
如果您id在 Elasticsearch 檔案中的單獨欄位中搜索,則可以使用以下查詢:
POST index1/_search
{
"query": {
"terms": {
"id": ["1","2","3"]
}
}
}
下面是等效的 .Net 代碼。
client.Search<MyDocument>(s => s
.Index("index1")
.Query(q => q
.Terms(t => t.Field(f => f.Name).Terms(ids))
)
);
uj5u.com熱心網友回復:
您可以使用術語查詢來實作您的用例,在 JSON 中它如下所示。
GET /_search
{
"query": {
"terms": {
"tbl.id": [ 1,2,4 ],
"boost": 1.0
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/464130.html
上一篇:如何更改非常大的ElasticSearch索引上的映射型別?
下一篇:ElasticsearchFilebeat忽略自定義索引模板,并使用默認filebeat索引模板覆寫輸出索引的映射
