gpt4 book ai didi

elasticsearch - Elasticsearch 7.7如何读取多个文档,而不是获取所有文档

转载 作者:行者123 更新时间:2023-12-03 01:13:45 26 4
gpt4 key购买 nike

我在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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com