我在弹性搜索中有一个索引。
样品结构:
{
"Article": "Article7645674712",
"Genre": "Genre92231455",
"relationDesc": [
"Article",
"Genre"
],
"org": "user",
"dateCreated": {
"date": "08/05/2015",
"time": "16:22 IST"
},
"dateModified": "08/05/2015"
}
Run Code Online (Sandbox Code Playgroud)
我想从该索引中检索选定的字段:org和dateModified。
我想要这样的结果
{
"took": 265,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 28,
"max_score": 1,
"hits": [
{
"_index": "couchrecords",
"_type": "couchbaseDocument",
"_id": "3",
"_score": 1,
"_source": {
"doc": {
"org": "user",
"dateModified": "08/05/2015"
}
}
},
{
"_index": "couchrecords",
"_type": "couchbaseDocument",
"_id": "4",
"_score": 1,
"_source": {
"doc": {
"org": "user",
"dateModified": "10/05/2015"
}
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
如何查询弹性搜索以仅获取选定的特定字段?
您可以使用_source参数仅在结果匹配中检索一组特定的字段,如下所示:
curl -XGET localhost:9200/couchrecords/couchbaseDocument/_search?_source=org,dateModified
Run Code Online (Sandbox Code Playgroud)
或采用以下格式:
curl -XPOST localhost:9200/couchrecords/couchbaseDocument/_search -d '{
"_source": ["doc.org", "doc.dateModified"], <---- you just need to add this
"query": {
"match_all":{} <----- or whatever query you have
}
}'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5230 次 |
最近记录: |