forked from gsingers/search_with_machine_learning_course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-data.sh
executable file
·56 lines (46 loc) · 2.43 KB
/
index-data.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
usage()
{
echo "Usage: $0 [-p /path/to/bbuy/products/field/mappings] [ -q /path/to/bbuy/queries/field/mappings ] [ -b /path/to/bbuy/products/logstash/conf ] [ -e /path/to/bbuy/queries/logstash/conf ] [ -l /path/to/logstash/home ] [ -g /path/to/write/logs/to ]"
exit 2
}
PRODUCTS_JSON_FILE="/workspace/search_with_machine_learning_course/opensearch/bbuy_products.json"
QUERIES_JSON_FILE="/workspace/search_with_machine_learning_course/opensearch/bbuy_queries.json"
PRODUCTS_LOGSTASH_FILE="/workspace/search_with_machine_learning_course/logstash/index-bbuy.logstash"
QUERIES_LOGSTASH_FILE="/workspace/search_with_machine_learning_course/logstash/index-bbuy-queries.logstash"
LOGSTASH_HOME="/workspace/logstash/logstash-7.13.2"
LOGS_DIR="/workspace/logs"
while getopts ':p:q:b:e:g:l:h' c
do
case $c in
p) PRODUCTS_JSON_FILE=$OPTARG ;;
q) QUERIES_JSON_FILE=$OPTARG ;;
b) PRODUCTS_LOGSTASH_FILE=$OPTARG ;;
e) QUERIES_LOGSTASH_FILE=$OPTARG ;;
g) LOGS_DIR=$OPTARG ;;
l) LOGSTASH_HOME=$OPTARG ;;
h) usage ;;
[?]) usage ;;
esac
done
shift $((OPTIND -1))
echo "Creating index settings and mappings"
echo " Product file: $PRODUCTS_JSON_FILE"
echo " Query file: $QUERIES_JSON_FILE"
curl -k -X PUT -u admin "https://localhost:9200/bbuy_products" -H 'Content-Type: application/json' -d "@$PRODUCTS_JSON_FILE"
echo ""
curl -k -X PUT -u admin "https://localhost:9200/bbuy_queries" -H 'Content-Type: application/json' -d "@$QUERIES_JSON_FILE"
echo ""
echo "Writing logs to $LOGS_DIR"
mkdir -p $LOGS_DIR
echo "Indexing"
echo " Product Logstash file: $PRODUCTS_LOGSTASH_FILE"
echo " Query Logstash file: $QUERIES_LOGSTASH_FILE"
echo "Running Logstash found in $LOGSTASH_HOME"
cd "$LOGSTASH_HOME"
echo "Launching Logstash indexing in the background via nohup. See product_indexing.log and queries_indexing.log for log output"
echo " Cleaning up any old indexing information by deleting products_data. If this is the first time you are running this, you might see an error."
rm -rf "$LOGSTASH_HOME/products_data"
nohup bin/logstash --pipeline.workers 7 --path.data ./products_data -f "$PRODUCTS_LOGSTASH_FILE" > "$LOGS_DIR/product_indexing.log" &
echo " Cleaning up any old indexing information by deleting query_data. If this is the first time you are running this, you might see an error."
rm -rf "$LOGSTASH_HOME/query_data"
nohup bin/logstash --pipeline.workers 1 --path.data ./query_data -f "$QUERIES_LOGSTASH_FILE" > "$LOGS_DIR/queries_indexing.log" &