0
我正在实施自定义本机SearchScript
,在查询执行时产生一定的分数。给定术语x
,脚本应该计算一个索引内文档集的相似性度量。搜索脚本应该使用ScriptEngineService
实例进行编译和执行。然而,问题在于,如果已使用映射端点明确定义了字段,则无法在该段中找到该字段。ElasticSearch 5.5 SearchScript
@Override
public Function<Map<String,Object>,SearchScript> compile(String scriptName, String scriptSource, Map<String, String> params) {
if ("script".equals(scriptSource)) {
return p -> new SearchScript() {
final String field;
final String term;
{
field = p.get("field").toString();
term = p.get("term").toString();
}
@Override
public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException {
PostingsEnum postings = context.reader().postings(new Term(field), PostingsEnum.PAYLOAD);
if (postings == null) {
// The field has not been found within the segment.
return() -> 0;
}
任何暗示到,为什么不能被发现含有特定领域没有文件?