From 373115fa30874a444592cfad88366a31905f495c Mon Sep 17 00:00:00 2001 From: "ICKostiantyn.Ivanov" Date: Thu, 18 Sep 2025 15:24:51 +0200 Subject: [PATCH] BAEL-9122 - Elastic Search Query with "not contains" --- .../bash/elasticsearch-notcontains-samples.sh | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 persistence-modules/elasticsearch/src/main/bash/elasticsearch-notcontains-samples.sh diff --git a/persistence-modules/elasticsearch/src/main/bash/elasticsearch-notcontains-samples.sh b/persistence-modules/elasticsearch/src/main/bash/elasticsearch-notcontains-samples.sh new file mode 100644 index 000000000000..bed57951795d --- /dev/null +++ b/persistence-modules/elasticsearch/src/main/bash/elasticsearch-notcontains-samples.sh @@ -0,0 +1,47 @@ +# Create new index +curl -X PUT "http://localhost:9200/transaction-logs" +-H "Content-Type: application/json" +-d' { "mappings": { "properties": { "message": { "type": "text", "fields": { "keyword": { "type": "keyword" } } } } } }' + +# Populate the test data +curl -X POST "http://localhost:9200/transaction-logs/_doc/1" +-H "Content-Type: application/json" +-d' { "message": "User1 deposited 1000 AP1 points" }' + +curl -X POST "http://localhost:9200/transaction-logs/_doc/2" +-H "Content-Type: application/json" +-d' { "message": "User1 deposited 1000 AP2 points" }' + +curl -X POST "http://localhost:9200/transaction-logs/_doc/3" +-H "Content-Type: application/json" +-d' { "message": "User1 deposited 1000 AP3 points" }' + +curl -X POST "http://localhost:9200/transaction-logs/_doc/4" +-H "Content-Type: application/json" +-d' { "message": "User1 deposited 1000 PP1 points" }' + +# Regexp With must_not +curl -X GET "http://localhost:9200/logs/_search" +-H "Content-Type: application/json" +-d' { "query": { "bool": { "must_not": [ { "regexp": { "message.keyword": ".*AP[2-9].*" } } ] } } }' + + +# Wildcard With must_not +curl -X GET "http://localhost:9200/transaction-logs/_search" +-H "Content-Type: application/json" +-d' { "query": { "bool": { "must_not": [ { "wildcard": { "message.keyword": "*AP*" } } ] } } }' + +# Query String With must_not +curl -X GET "http://localhost:9200/transaction-logs/_search" +-H "Content-Type: application/json" +-d' { "query": { "bool": { "must_not": [ { "query_string": { "query": "message:*AP*"} } ] } } }' + +# Create new index with customized analyzer +curl -X PUT "localhost:9200/transaction-logs" +-H "Content-Type: application/json" +-d' { "settings": { "analysis": { "analyzer": { "message_analyzer": { "tokenizer": "whitespace", "filter": ["lowercase", "word_delimiter"] } } } }, "mappings": { "properties": { "message": { "type": "text", "analyzer": "message_analyzer" } } } }' + +# Match With must_not +curl -X GET "http://localhost:9200/transaction-logs/_search" +-H "Content-Type: application/json" +-d' { "query": { "bool": { "must_not": [ { "match": { "message": "AP" } } ] } } }' \ No newline at end of file