基本命令
- q指定查询语句
- df 默认字段,不指定时,会对所有字段进行查询
- sort排序 / from size 用于排序
- Profile 可以显示查询是如何执行.
查询示例
GET /movies/_search?q=2012&df=title
{
"profile":"true"
}
可以看看结果

这里我们看可以看到 返回了2条数据

这里我们可以看到
type为"TermQuery"
description为"title:2012"
# 对所有字段就行查询(性能不好)
GET /movies/_search?q=2012
{
"profile": "true"
}
# 对指定字段进行查询(这里和采用df指定字段是一样的)
GET /movies/_search?q=title:2012
{
"profile": "true"
}
# AND查询的title包含 Beautiful 和 Mind 这2个单词的(这里前后顺序要求一致)
GET /movies/_search?q=title:"Beautiful Mind"
{
"profile": "true"
}
# OR查询的title包含 Beautiful 或 Mind (这里是没有引号的)
GET /movies/_search?q=title:Beautiful Mind
{
"profile": "true"
}
# 布尔查询用"()"包起来 title 必需包含 Beautiful 或 Mind
GET /movies/_search?q=title:(Beautiful Mind)
{
"profile": "true"
}
# 包含 Beautiful 并且 包含 Mind
GET /movies/_search?q=title:(Beautiful AND Mind)
{
"profile": "true"
}
# 包含 Beautiful 并且不包含 Mind
GET /movies/_search?q=title:(Beautiful NOT Mind)
{
"profile": "true"
}
# 范围查询 year 大于等于1980
GET /movies/_search?q=year:>=1980
{
"profile": "true"
}
# 通配符查询 title包含b
GET /movies/_search?q=title:b*
{
"profile": "true"
}
# 模糊匹配查询
GET /movies/_search?q=title:beautifl~1
{
"profile": "true"
}
本文详细介绍了Elasticsearch的基本命令,如q参数的使用、df选择字段、sort和fromsize排序,以及Profile功能展示查询执行。通过实例演示了各种查询类型,包括精确匹配、OR查询、布尔查询和范围查询。适合深入理解搜索引擎操作技巧。
341

被折叠的 条评论
为什么被折叠?



