You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-8Lines changed: 84 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,8 @@
4
4
[](https://packagist.org/packages/ginkelsoft/laravel-encrypted-search-index)
@@ -36,14 +36,15 @@ This package removes that trade-off by introducing a **detached searchable index
36
36
***Detached search index** — Tokens are stored separately from the main data, reducing exposure risk.
37
37
***Deterministic hashing with peppering** — Each token is derived from normalized text combined with a secret pepper.
38
38
***No blind indexes in primary tables** — Encrypted fields remain opaque; only hashed references are stored elsewhere.
39
-
***High scalability** — Efficient for millions of records through database indexing.
39
+
***High scalability** — Efficient for millions of records through database indexing or Elasticsearch.
40
+
***Elasticsearch integration** — Optionally store and query search tokens directly in an Elasticsearch index.
40
41
***Laravel-native integration** — Works directly with Eloquent models, query scopes, and model events.
41
42
42
43
---
43
44
44
45
## How It Works
45
46
46
-
Each model can declare specific fields as searchable. When the model is saved, the system normalizes the field value, generates one or more hashed tokens, and stores them in a separate table named `encrypted_search_index`.
47
+
Each model can declare specific fields as searchable. When the model is saved, the system normalizes the field value, generates one or more hashed tokens, and stores them in a separate table named `encrypted_search_index`**or** in an Elasticsearch index if configured.
47
48
48
49
When you search, the package hashes your input using the same process and retrieves matching model IDs from the index.
49
50
@@ -56,7 +57,9 @@ For each configured field:
56
57
57
58
### 2. Token Storage
58
59
59
-
All tokens are stored in `encrypted_search_index`:
60
+
By default, all tokens are stored in the database table `encrypted_search_index`. When Elasticsearch is enabled, they are stored in the configured Elasticsearch index instead.
When enabled, the package will **skip database writes** to `encrypted_search_index` and instead sync tokens directly to Elasticsearch via the `ElasticsearchService`.
110
+
111
+
### Searching via Elasticsearch
112
+
113
+
To manually query Elasticsearch for a specific token:
114
+
115
+
```bash
116
+
curl -X GET "http://localhost:9200/encrypted_search/_search?pretty" \
117
+
-H 'Content-Type: application/json' \
118
+
-d '{
119
+
"query": {
120
+
"term": {
121
+
"token.keyword": "<your-token-here>"
122
+
}
123
+
}
124
+
}'
125
+
```
126
+
127
+
For prefix-based queries, you can match multiple tokens:
128
+
129
+
```bash
130
+
curl -X GET "http://localhost:9200/encrypted_search/_search?pretty" \
0 commit comments