Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
opensearch [2025/03/25 01:02] jango |
opensearch [2025/03/27 11:49] (aktuell) jango |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | Siehe auch [[ElasticSearch]] (z.B Scripte, API, etc. sind identisch). [[Wazuh]] verwendet [[OpenSearch]]. | ||
+ | |||
=====Installation===== | =====Installation===== | ||
Zeile 21: | Zeile 23: | ||
) | ) | ||
client.info() | client.info() | ||
+ | </ | ||
+ | |||
+ | Get some random data for e.g [[https:// | ||
+ | |||
+ | <code python> | ||
+ | import pandas as pd | ||
+ | |||
+ | df = ( | ||
+ | pd.read_csv(" | ||
+ | .dropna() | ||
+ | .sample(5000, | ||
+ | .reset_index(drop=True) | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | Create an index | ||
+ | |||
+ | <code python> | ||
+ | body = { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | response = client.indices.create(" | ||
+ | </ | ||
+ | |||
+ | Push the data into the index | ||
+ | |||
+ | <code python> | ||
+ | for i, row in df.iterrows(): | ||
+ | body = { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | client.index(index=" | ||
+ | </ | ||
+ | |||
+ | More data in a bulk | ||
+ | |||
+ | <code python> | ||
+ | from opensearchpy.helpers import bulk | ||
+ | |||
+ | bulk_data = [] | ||
+ | for i,row in df.iterrows(): | ||
+ | bulk_data.append( | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | ) | ||
+ | bulk(client, | ||
+ | </ | ||
+ | |||
+ | Count the inserted data | ||
+ | |||
+ | <code python> | ||
+ | client.indices.refresh(index=" | ||
+ | client.cat.count(index=" | ||
+ | </ | ||
+ | |||
+ | Search the data | ||
+ | |||
+ | <code python> | ||
+ | resp = client.search( | ||
+ | index=" | ||
+ | body={ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | }, | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | } | ||
+ | ) | ||
+ | resp | ||
+ | </ | ||
+ | |||
+ | Remove documents | ||
+ | <code python> | ||
+ | client.delete(index=" | ||
+ | </ | ||
+ | |||
+ | Delete the index | ||
+ | <code python> | ||
+ | client.indices.delete(index=' | ||
</ | </ |