原英文版地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/sql-client-apps-ps1.html, 原文档版权归 www.elastic.co 所有
本地英文版地址: ../en/sql-client-apps-ps1.html
本地英文版地址: ../en/sql-client-apps-ps1.html
重要: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 当前版本文档。
Microsoft PowerShelledit
You can use the Elasticsearch ODBC driver to access Elasticsearch data from Microsoft PowerShell.
Elastic does not endorse, promote or provide support for this application; for native Elasticsearch integration in this product, please reach out to its vendor.
Prerequisitesedit
- Microsoft PowerShell
- Elasticsearch SQL ODBC driver
- A preconfigured User or System DSN (see Configuration section on how to configure a DSN).
Writing a scriptedit
While putting the following instructions into a script file is not an absolute requirement, doing so will make it easier to extend and
reuse. The following instructions exemplify how to execute a simple SELECT query from an existing index in your Elasticsearch instance, using a DSN
configured in advance. Open a new file, select.ps1
, and place the following instructions in it:
$connectstring = "DSN=Local Elasticsearch;" $sql = "SELECT * FROM library" $conn = New-Object System.Data.Odbc.OdbcConnection($connectstring) $conn.open() $cmd = New-Object system.Data.Odbc.OdbcCommand($sql,$conn) $da = New-Object system.Data.Odbc.OdbcDataAdapter($cmd) $dt = New-Object system.Data.datatable $null = $da.fill($dt) $conn.close() $dt
Now open a PowerShell shell and simply execute the script: