![]() |
VOOZH | about |
The CData Cmdlets Module for Elasticsearch is a standard PowerShell module offering straightforward integration with Elasticsearch. Below, you will find examples of using our Elasticsearch Cmdlets with native PowerShell cmdlets.
Accessing and integrating live data from Elasticsearch has never been easier with CData. Customers rely on CData connectivity to:
Users frequently integrate Elasticsearch data with analytics tools such as Crystal Reports, Power BI, and Excel, and leverage our tools to enable a single, federated access layer to all of their data sources, including Elasticsearch.
For more information on CData's Elasticsearch solutions, check out our Knowledge Base article: CData Elasticsearch Driver Features & Differentiators.
Set the Server and Port connection properties to connect. To authenticate, set the User and Password properties, PKI (public key infrastructure) properties, or both. To use PKI, set the SSLClientCert, SSLClientCertType, SSLClientCertSubject, and SSLClientCertPassword properties.
The data provider uses X-Pack Security for TLS/SSL and authentication. To connect over TLS/SSL, prefix the Server value with 'https://'. Note: TLS/SSL and client authentication must be enabled on X-Pack to use PKI.
Once the data provider is connected, X-Pack will then perform user authentication and grant role permissions based on the realms you have configured.
$conn = Connect-Elasticsearch -Server "$Server" -Port "$Port" -User "$User" -Password "$Password"
Follow the steps below to retrieve data from the Orders table and pipe the result into to a CSV file:
Select-Elasticsearch -Connection $conn -Table Orders | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myOrdersData.csv -NoTypeInformation
You will notice that we piped the results from Select-Elasticsearch into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.
The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.The following line deletes any records that match the criteria:
Select-Elasticsearch -Connection $conn -Table Orders -Where "ShipCity = New York" | Remove-Elasticsearch
The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Elasticsearch, checking first whether a record already exists and needs to be updated instead of inserted.
Import-Csv -Path C:\MyOrdersUpdates.csv | %{
$record = Select-Elasticsearch -Connection $Elasticsearch -Table Orders -Where ("Id = `'"+$_.Id+"`'")
if($record){
Update-Elasticsearch -Connection $elasticsearch -Table Orders -Columns ("OrderName","Freight") -Values ($_.OrderName, $_.Freight) -Where ("Id = `'"+$_.Id+"`'")
}else{
Add-Elasticsearch -Connection $elasticsearch -Table Orders -Columns ("OrderName","Freight") -Values ($_.OrderName, $_.Freight)
}
}
As always, our goal is to simplify the way you connect to data. With cmdlets users can install a data module, set the connection properties, and start building. Download Cmdlets and start working with your data in PowerShell today!
Download a free trial of the Elasticsearch Cmdlets to get started:
Download NowLearn more:
👁 Elasticsearch IconAn easy-to-use set of PowerShell Cmdlets offering real-time access to Elasticsearch data. The Cmdlets allow users to easily read, write, update, and delete live data - just like working with SQL server.