3 . "${_EXEC:-${0%/*}}/cgilite/cgilite.sh"
4 . "${_EXEC:-${0%/*}}/cgilite/storage.sh"
5 . "${_EXEC:-${0%/*}}/cgilite/json.sh"
7 [ "$_DATE" ] || _DATE="$(date +%s)"
9 _INDEX="${PATH_INFO#/}" _INDEX="${_INDEX%%/*}"
10 _records="${_DATA}/${_INDEX}/_0_DOCS"
16 # json_get "$J" parts.comments
18 case $(json_get "$J" title) in
20 json_get "$J" content |base64 -d
23 json_get "$J" content |base64 -d \
27 json_get "$J" content |base64 -d \
31 json_get "$J" content |base64 -d \
35 json_get "$J" content |base64 -d \
39 json_get "$J" content |base64 -d \
43 json_get "$J" content |base64 -d \
44 | unzip -qc /dev/stdin word/document.xml \
45 | head -c 128M | sed 's;<[^>]*>;;g'
48 json_get "$J" content |base64 -d \
49 | unzip -qc /dev/stdin xl/sharedStrings.xml \
50 | head -c 128M | sed 's;<[^>]*>; ;g'
53 json_get "$J" content |base64 -d \
54 | unzip -qc /dev/stdin content.xml \
55 | head -c 128M | sed 's;<[^>]*>;;g'
58 json_get "$J" content |base64 -d \
59 | unzip -qc /dev/stdin content.xml \
60 | head -c 128M | sed 's;<[^>]*>; ;g'
66 if [ "$REQUEST_METHOD" = "PUT" ]; then
67 _doc="${PATH_INFO#"/${_INDEX}/_doc"}"
69 J="$(json_load "$(head -c "${CONTENT_LENGTH:-0}")")"
72 | "${_EXEC}/concordance.sh" \
73 "$_DATA/$_INDEX/" "$(STRING "$_doc") $_DATE"
76 J="$(DB2 "$J" delete content)"
77 J="$(DB2 "$J" set _indexdate num:"$_DATE")"
79 if DBM "$_records" insert "$_doc" "$J"; then
80 printf '%s: %s\r\n' "Status" "201 Created" "Location" "/${_INDEX}/_doc/$(URL "$_doc")" \
82 elif DBM "$_records" update "$_doc" "$J"; then
83 printf '%s: %s\r\n' "Status" "200 OK"
86 printf '%s\r\n' "Status: 500 Internal Server Error" ""
91 X-elastic-product: Elasticsearch
92 content-type: application/vnd.elasticsearch+json;compatible-with=8
94 { "_index": $(json_dump str:"${_INDEX}"),
95 "_id": $(json_dump str:"$_doc"),
102 elif [ "$REQUEST_METHOD" = "DELETE" ]; then
103 _doc="${PATH_INFO#"/${_INDEX}/_doc"}"
105 if DBM "$_records" get "$_doc"; then
106 if DBM "$_records" delete "$_doc"; then
107 printf '%s: %s\r\n' "Status" "200 OK"
110 printf '%s\r\n' "Status: 500 Internal Server Error" ""
114 printf '%s: %s\r\n' "Status" "404 Not Found"
119 X-elastic-product: Elasticsearch
120 content-type: application/vnd.elasticsearch+json;compatible-with=8
122 { "_index": $(json_dump str:"${_INDEX}"),
123 "_id": $(json_dump str:"$_doc"),
130 elif [ "$REQUEST_METHOD" = "POST" ]; then
132 elif [ "$REQUEST_METHOD" = "HEAD" ]; then
133 accept="$(HEADER Accept)"
134 [ ! "${accept#*"vnd.elasticsearch+json"*}" ] \
135 && ctype="${accept}" || ctype="application/json"
139 X-elastic-product: Elasticsearch
140 content-type: ${ctype}
144 elif [ "$REQUEST_METHOD" = "GET" ]; then
145 accept="$(HEADER Accept)"
146 [ ! "${accept#*"vnd.elasticsearch+json"*}" ] \
147 && ctype="${accept}" || ctype="application/json"
151 X-elastic-product: Elasticsearch
152 content-type: ${ctype}
156 if [ "$PATH_INFO" = "/${_INDEX}/" ]; then
158 { $(json_dump str:"${_INDEX}"): {
162 "content": {"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
163 "hash":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
164 "metatags":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
165 "owner":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
166 "parts":{"properties":{"comments":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},
167 "provider":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
168 "share_names":{"properties":{"paul":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},
169 "source":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
170 "title":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}
175 "routing":{"allocation":{"include":{"_tier_preference":"data_content"}}},
176 "number_of_shards":"1",
177 "provided_name": $(json_dump str:"${_INDEX}"),
178 "creation_date": "$(stat -c %W "${_DATA}/${_INDEX}")",
179 "number_of_replicas":"1",
180 "uuid":"0000000000000000000000",
181 "version":{"created":"8500010"}
190 "cluster_name" : "elasticsearch",
193 "lucene_version" : "9.9.2",
194 "minimum_wire_compatibility_version" : "7.17.0",
195 "minimum_index_compatibility_version" : "7.0.0"
197 "tagline" : "You Know, for Search"
204 printf '%s\r\n' "Status: 500 Internal Server Error" ""