您的位置:首页 > 新闻 > 热点要闻 > ElasticSearch常用DSL命令

ElasticSearch常用DSL命令

2025/5/9 15:24:33 来源:https://blog.csdn.net/NoviceZ/article/details/141823416  浏览:    关键词:ElasticSearch常用DSL命令

1、查询索引字段的映射关系

GET /索引/_mapping

2、查询索引的分词器等设置

GET /索引/_settings

3、根据指定分词器分词

GET /索引/_analyze
{"analyzer" : "standard","text" : "层系"
}

4、term查询

POST /索引/_search
{"query": {"term": {"dbId": "101545"}}
}

5、match查询 

POST /tb/_search
{"query": {"match": {"dbId": "19841159f25845008fad2512aa91f48b"}}
}

 6、bool查询

        6.1 must组合
GET /tb/_search
{"query": {"bool": {"must": [{"terms": {"dbId": [287994]}},{"match": {"original": "层"}}]}}
}

must类似于mysql里面的and命令,上述命令相当于MySQL里面的 where dbId in(287994) and original like '%层%'。注意此处把match命令当成了mysql的like命令,其实这两个命令还是有明显区别的。

        6.2must与should组合
POST /tb/_search
{"query": {"bool": {"must": [{"term": {"dbId": {"value": "19841159f25845008fad2512aa91f48b"}}}],"should": [{"match": {"original": "边水"}}],"minimum_should_match": 1}}
}

上述命令类似于MySQL命令:where dbId = '19841159f25845008fad2512aa91f48b' and original like '%边水%'。如果上述命令不加上minimum_should_match: 1,则类似于MySQL命令:where dbId = '19841159f25845008fad2512aa91f48b'。

7、自定义脚本过滤

GET /tb/_search
{"query": {"bool": {"must": [{"terms": {"dbId": ["19841159f25845008fad2512aa91f48b"]}},{"match_phrase": {"original.standard": {"query": "层系"}}}],"filter": [{"script": {"script": {"lang": "painless","source": "String str = params.val;String strLower = params.valLower;String val = doc['original.keyword'].value;return str.contains(val) || strLower.contains(val.toLowerCase());","params": {"val": "侏罗层系主力区块年注采比变化","valLower": "侏罗层系主力区块年注采比变化"}}}}]}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com