这看起来可能像hack,但是可以肯定地起作用。首先,我们将令牌计数类型与多字段一起应用以捕获令牌数量作为字段。因此,映射将如下所示-
{ "record" : { "properties" : { "LIN" : { "type" : "string", "fields" : { "word_count": { "type" : "token_count", "store" : "yes", "analyzer" : "standard" } } } } }}链接-http: //www.elasticsearch.org/guide/zh-
CN/elasticsearch/reference/current/mapping-core-
types.html#token_count
因此,要检查第二个字段是否存在,就像检查此字段值是否大于或等于2一样容易。接下来,我们可以使用令牌过滤器来检查令牌“
up”在位置0中是否存在。脚本过滤器对此进行检查。因此,如下所示的查询应该有效-
{ "query": { "filtered": { "query": { "range": { "LIN.word_count": { "gte": 2 } } }, "filter": { "script": { "script": "for(pos : _index['LIN'].get('up',_POSITIONS)){ if(pos.position == 0) { return true}};return false;" } } } }}高级脚本-http: //www.elasticsearch.org/guide/zh-
CN/elasticsearch/reference/current/modules-advanced-
scripting.html
脚本过滤器-http: //www.elasticsearch.org/guide/zh-
CN/elasticsearch/reference/current/query-dsl-script-
filter.html



