Skip to content

Conversation

@arnesetzer
Copy link
Contributor

👋 I did some awesome work for the Pelias project and would love for everyone to have a look at it and provide feedback.


Here's the reason for this change 🚀


Here's what actually got changed 👏

git diff  HEAD~2 HEAD
diff --git a/cmd/elastic.sh b/cmd/elastic.sh
index 701c19c..8a753e4 100644
--- a/cmd/elastic.sh
+++ b/cmd/elastic.sh
@@ -62,7 +62,14 @@ function elastic_info(){ curl -s "http://${ELASTIC_HOST:-localhost:9200}/"; }
 register 'elastic' 'info' 'display elasticsearch version and build info' elastic_info
 
 function elastic_stats(){

+  #Extract the API section from the pelias.json
+  api_section=$(cat "$DATA_DIR/../pelias.json" | sed -n '/"api": {/,/}/p')
+  #Extract the value of api.indexName
+  index_name=$(echo "$api_section" | grep '"indexName"' | sed 's/.*"indexName": "\(.*\)".*/\1/')
+  #Add info which index is queried
+  echo "Results for index \"${index_name:-"pelias"}\":"
+  #Query the index in question or use the default name (pelias)
+  curl -s "http://${ELASTIC_HOST:-localhost:9200}/${index_name:-"pelias"}/_search?request_cache=true&timeout=10s&pretty=true" \
-  curl -s "http://${ELASTIC_HOST:-localhost:9200}/pelias/_search?request_cache=true&timeout=10s&pretty=true" \

The code is a little bit hacky but I thought it was reasonable to not relay on external tools like jq.


Here's how others can test the changes 👀

  1. Change pelias.json like
"schema": {
    "indexName": "everything except pelias"
},
"api": {
    "indexName": "everything except pelias"
}
  1. Import some data
  2. Execute pelias elastic stats
    Should now show Results for index "everything except pelias": and the results for the index "everything except pelias".

cmd/elastic.sh Outdated
function elastic_stats(){
curl -s "http://${ELASTIC_HOST:-localhost:9200}/pelias/_search?request_cache=true&timeout=10s&pretty=true" \
#Extract the API section from the pelias.json
api_section=$(cat "$DATA_DIR/../pelias.json" | sed -n '/"api": {/,/}/p')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pelias.json file is not always relative to the $DATA_DIR.

cmd/elastic.sh Outdated
#Extract the API section from the pelias.json
api_section=$(cat "$DATA_DIR/../pelias.json" | sed -n '/"api": {/,/}/p')
#Extract the value of api.indexName
index_name=$(echo "$api_section" | grep '"indexName"' | sed 's/.*"indexName": "\(.*\)".*/\1/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to avoid using sed if possible, jq would be good option if it didn't introduce an external dependency. maybe node -e is the best option for this and the above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but only when the node_modules directory is present, which it isn't for the docker bash scripts 😿

node -e "console.log(require('pelias-config').generate().schema.indexName)"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's best to move this into the pelias/schema module and then call it through docker?

Copy link
Contributor Author

@arnesetzer arnesetzer Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should resolve all the current problems.

@arnesetzer
Copy link
Contributor Author

Blocked by pelias/schema#507

@missinglink
Copy link
Member

Sorry to flip-flop so much on this, would this small change suffice?

diff --git a/cmd/elastic.sh b/cmd/elastic.sh
index 701c19c..030b163 100644
--- a/cmd/elastic.sh
+++ b/cmd/elastic.sh
@@ -62,7 +62,7 @@ function elastic_info(){ curl -s "http://${ELASTIC_HOST:-localhost:9200}/"; }
 register 'elastic' 'info' 'display elasticsearch version and build info' elastic_info

 function elastic_stats(){
-  curl -s "http://${ELASTIC_HOST:-localhost:9200}/pelias/_search?request_cache=true&timeout=10s&pretty=true" \
+  curl -s "http://${ELASTIC_HOST:-localhost:9200}/${ELASTIC_INDEX:-'pelias'}/_search?request_cache=true&timeout=10s&pretty=true" \
     -H 'Content-Type: application/json' \
     -d '{
           "aggs": {

@arnesetzer
Copy link
Contributor Author

The last commit loops the parameter, if present, in the schema container, so it is possible to use the same syntax. If no indexName is given in the config, it falls back to defaults.json, which is pelias. Personally, I prefer this solution because it eliminates a static name, which was the reason for this PR in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pelias elastic stats has the default index hardcoded

2 participants