如何解决Elasticsearch 7.7如何读取多个文档,而不是获取所有文档
我在CentOS 8框中使用ElasticSearch 7.7。我可以创建索引,通过命令curl以REST格式键入。例如,我可以使用
curl -X PUT "localhost:9200/testindex2"
curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/testindex2/man/1/" -d '{ "name" : "shiny2","age": 28}'
curl -XGET "localhost:9200/testindex2/man/1/"
curl -XGET "localhost:9200/testindex2/man/_search?pretty"
但是,如果我插入了许多文档,如何使用REST
命令通过curl
命令行查询来查找特定的age = 28's
文档?
解决方法
curl -XGET "localhost:9200/testindex2/_search?pretty&q=age:28"
这是最简单的查询方式。
更多选项和文档:
https://www.elastic.co/guide/en/elasticsearch/reference/7.8/search-search.html
您还可以使用JSON正文格式的Match或Term查询。
curl -XGET 'localhost:9200/testindex2/_search?pretty' -d '
{
"query": {
"term": {
"age": {
"value": "28"
}
}
}
}'
更多文档:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。