我在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
关于elasticsearch - Elasticsearch 7.7如何读取多个文档,而不是获取所有文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63373576/