I am trying to run ElasticSearch query to calculate a distance.
- Version of ElasticSearch is 1.7.2 and Java 1.7.0_79.
- Using PHP Framework TYPO3 Flow
- With Neos ElasticSearch Adapter
Description:
I have list of companies that are retrieved by ElasticSearch. User can search for a company by it's name and location. Here the location is the problem. When I search by location I am loosing my pagination.
Example Situation:
- Set itemsPerPage of pagination to 10
- Run search -> I can see i.e. 10 items and no pagination
- Set itemsPerPage of pagination to 2 -> expected result is 5 pages
- 2 items are listed and no pagination
Template of pagination:
{namespace search=TYPO3\TYPO3CR\Search\ViewHelpers}
<search:widget.paginate query="{searchQuery}" as="results" configuration="{'itemsPerPage': 2}">
<ts:render path="searchResultRenderer" context="{searchResults: results}"/>
</search:widget.paginate>
Java error:
org.elasticsearch.index.query.QueryParsingException: [typo3cr-1444378386] request does not support [script_fields]
at org.elasticsearch.index.query.IndexQueryParserService.parseQuery(IndexQueryParserService.java:360)
at org.elasticsearch.action.count.TransportCountAction.shardOperation(TransportCountAction.java:187)
at org.elasticsearch.action.count.TransportCountAction.shardOperation(TransportCountAction.java:66)
at org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction$AsyncBroadcastAction$1.run(TransportBroadcastOperationAction.java:170)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
ElasticSearch configuration.yml:
# The following settings are absolutely required for the CR adaptor to work
script.file: on
script.inline: sandbox
script.indexed: sandbox
script.engine.groovy.inline: sandbox
script.engine.groovy.indexed: sandbox
script.groovy.sandbox.class_whitelist: java.util.LinkedHashMap
script.groovy.sandbox.receiver_whitelist: java.util.Iterator, java.lang.Object, java.util.Map, java.util.Map$Entry
script.groovy.sandbox.enabled: true
# the following settings are well-suited for smaller ElasticSearch instances (e.g. as long as you can stay on one host)
index.number_of_shards: 1
index.number_of_replicas: 0
The query I run is:
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"match_all": []
},
{
"query_string": {
"query": "*"
}
}
]
}
},
"filter": {
"bool": {
"must": [
{
"term": {
"__parentPath": "/sites/project"
}
},
{
"terms": {
"__workspace": [
"live"
]
}
},
{
"term": {
"__typeAndSupertypes": "Project:Entry"
}
}
],
"should": [],
"must_not": [
{
"term": {
"_hidden": true
}
},
{
"range": {
"_hiddenBeforeDateTime": {
"gt": "now"
}
}
},
{
"range": {
"_hiddenAfterDateTime": {
"lt": "now"
}
}
}
]
}
}
}
},
"script_fields": {
"distance": {
"script": "doc['coordinates'].distanceInKm(52.39266079999999,9.768640199999936)"
}
}
}