Skip to content

Commit e3adc06

Browse files
committed
TASK: Move Version5 scripts from stored to inline
This is required since ElasticSearch on AWS only supports inline scripts.
1 parent 50c3592 commit e3adc06

2 files changed

Lines changed: 34 additions & 66 deletions

File tree

Classes/Driver/Version5/IndexerDriver.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ public function document($indexName, NodeInterface $node, ElasticSearchDocument
4242
'_retry_on_conflict' => 3
4343
]
4444
],
45-
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/2.4/docs-update.html
45+
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/5.0/docs-update.html
4646
[
4747
'script' => [
48-
'stored' => 'updateFulltextParts',
48+
'lang' => 'painless',
49+
'inline' => '
50+
HashMap fulltext = (ctx._source.containsKey("__fulltext") ? ctx._source.__fulltext : new HashMap());
51+
HashMap fulltextParts = (ctx._source.containsKey("__fulltextParts") ? ctx._source.__fulltextParts : new HashMap());
52+
ctx._source = params.newData;
53+
ctx._source.__fulltext = fulltext;
54+
ctx._source.__fulltextParts = fulltextParts',
4955
'params' => [
5056
'newData' => $documentData
5157
]
@@ -114,7 +120,32 @@ public function fulltext(NodeInterface $node, array $fulltextIndexOfNode, $targe
114120
[
115121
// first, update the __fulltextParts, then re-generate the __fulltext from all __fulltextParts
116122
'script' => [
117-
'stored' => 'regenerateFulltext',
123+
'lang' => 'painless',
124+
'inline' => '
125+
ctx._source.__fulltext = new HashMap();
126+
if (!ctx._source.containsKey("__fulltextParts")) {
127+
ctx._source.__fulltextParts = new HashMap();
128+
}
129+
130+
if (params.nodeIsRemoved || params.nodeIsHidden || params.fulltext.size() == 0) {
131+
if (ctx._source.__fulltextParts.containsKey(params.identifier)) {
132+
ctx._source.__fulltextParts.remove(params.identifier);
133+
}
134+
} else {
135+
ctx._source.__fulltextParts.put(params.identifier, params.fulltext);
136+
}
137+
138+
ctx._source.__fulltextParts.each {
139+
originNodeIdentifier, partContent -> partContent.each {
140+
bucketKey, content ->
141+
if (ctx._source.__fulltext.containsKey(bucketKey)) {
142+
value = ctx._source.__fulltext[bucketKey] + " " + content.trim();
143+
} else {
144+
value = content.trim();
145+
}
146+
ctx._source.__fulltext[bucketKey] = value;
147+
}
148+
}',
118149
'params' => [
119150
'identifier' => $node->getIdentifier(),
120151
'nodeIsRemoved' => $node->isRemoved(),

Classes/Driver/Version5/Mapping/NodeTypeMappingBuilder.php

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public function buildMappingInformation(Index $index)
5353

5454
$mappings = new MappingCollection(MappingCollection::TYPE_ENTITY);
5555

56-
$this->setupStoredScripts($index);
57-
5856
/** @var NodeType $nodeType */
5957
foreach ($this->nodeTypeManager->getNodeTypes() as $nodeTypeName => $nodeType) {
6058
if ($nodeTypeName === 'unstructured' || $nodeType->isAbstract()) {
@@ -104,67 +102,6 @@ public function buildMappingInformation(Index $index)
104102
return $mappings;
105103
}
106104

107-
/**
108-
* Store scripts used during indexing in Elasticsearch.
109-
*
110-
* @param Index $index
111-
* @return void
112-
*/
113-
protected function setupStoredScripts(Index $index)
114-
{
115-
$this->client->request(
116-
'POST',
117-
'/_scripts/updateFulltextParts',
118-
[],
119-
json_encode(['script' => [
120-
'lang' => 'painless',
121-
'code' => '
122-
HashMap fulltext = (ctx._source.containsKey("__fulltext") ? ctx._source.__fulltext : new HashMap());
123-
HashMap fulltextParts = (ctx._source.containsKey("__fulltextParts") ? ctx._source.__fulltextParts : new HashMap());
124-
ctx._source = params.newData;
125-
ctx._source.__fulltext = fulltext;
126-
ctx._source.__fulltextParts = fulltextParts'
127-
]
128-
])
129-
);
130-
131-
$this->client->request(
132-
'POST',
133-
'/_scripts/regenerateFulltext',
134-
[],
135-
json_encode(['script' => [
136-
'lang' => 'painless',
137-
'code' => '
138-
ctx._source.__fulltext = new HashMap();
139-
if (!ctx._source.containsKey("__fulltextParts")) {
140-
ctx._source.__fulltextParts = new HashMap();
141-
}
142-
143-
if (params.nodeIsRemoved || params.nodeIsHidden || params.fulltext.size() == 0) {
144-
if (ctx._source.__fulltextParts.containsKey(params.identifier)) {
145-
ctx._source.__fulltextParts.remove(params.identifier);
146-
}
147-
} else {
148-
ctx._source.__fulltextParts.put(params.identifier, params.fulltext);
149-
}
150-
151-
ctx._source.__fulltextParts.each {
152-
originNodeIdentifier, partContent -> partContent.each {
153-
bucketKey, content ->
154-
if (ctx._source.__fulltext.containsKey(bucketKey)) {
155-
value = ctx._source.__fulltext[bucketKey] + " " + content.trim();
156-
} else {
157-
value = content.trim();
158-
}
159-
ctx._source.__fulltext[bucketKey] = value;
160-
}
161-
}
162-
'
163-
]
164-
])
165-
);
166-
}
167-
168105
/**
169106
* Adjust the mapping for string to text or keyword as needed.
170107
*

0 commit comments

Comments
 (0)