我正在尝试运行 ElasticSearch 查询来计算距离。
- ElasticSearch 的版本是1.7.2和 Java 1.7.0_79。
- 使用 PHP 框架 TYPO3 流程
- 使用Neos ElasticSearch 适配器
描述:
我有 ElasticSearch 检索到的公司列表。用户可以通过名称和位置搜索公司。这里的位置是问题。当我按位置搜索时,我失去了分页。
示例情况:
- 将分页的 itemsPerPage 设置为 10
- 运行搜索-> 我可以看到 10 个项目并且没有分页
- 将分页的 itemsPerPage 设置为 2 -> 预期结果是 5 页
- 列出了 2 个项目并且没有分页
分页模板:
{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错误:
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 配置.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
我运行的查询是:
{
"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)"
}
}
}