使用elasticsearch时候对字段name使用排序,报错:
RemoteTransportException[[node-1][IP:9300][indices:data/read/search[phase/dfs]]]; nested: IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [XX] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.]; }
原因上面的已经说的很清楚,text类型的字段fielddata属性 默认= false,为什么呢?
因为text类型会被切分,例如New York 会被切分成New 和York,那es怎么知道你要说的是根据New还是York排序呢?所以你得告诉es,我要根据Now York来排序。
我的解决方式:
1.将存储到es的实体类的字段name 标为keyword
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import org.springframework.context.annotation.Profile;
import org.springframework.