1、分页最大数问题
es默认分页最大为1w,当我们分页数超过1w时会报错
解决方法:
如下法律法规分页查询最大支持100000
http://IP:端口/
yourindex/_settings PUT
{
"index": {
"max_result_window": 100000
}
}
2、分页出现重复数据问题
es分页查询如果不加sort排序,不同页会出现,不固定的重复数据
解决方法:
在查询时加上sort排序,任意排序都可以
3、索引字段超过256个字后无法进行查询
如下例子为es默认字段mappings属性
"mappings": {
"t_doc": {
"properties": {
"document_ids": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
}
}
其中的ignore_above表示字段进行索引的最大字数,当我们超过256个时,不进行索引且该属性有最大值限制 32766 / 3 = 10922个字符
解决方法:
当字符数在1w以内可以增加ignore_above属性值,如果超出比如我遇到的一个字段中存有100W个字符那么我们可以使用ik分词来索引字段
4、经验之谈分词与排序
在我们实际项目中往往需要用到复杂的排序,平时我们可以只用自定义分词等解决一些问题,但是当遇到一个分词字段要使用排序时,往往难以实现。所以我们开始设计字段时应该将字段分成分词与不分词并存。可以如下建立mappings:
"mappings": {
"t_law": {
"properties": {
"content": {
"type": "text",
"analyzer": "ik",
"search_analyzer": "ik_smart",
"index_options": "offsets",
"term_vector": "with_positions_offsets",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 10000
}
}
},
"lawTitle": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart",
"index_options": "offsets",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 10000
}
}
},
"content_txt": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart",
"index_options": "offsets",
"term_vector": "with_positions_offsets",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 10000
}
}
}
}
}
}
5、高亮对html字段
高亮显示会对html支持并不友好,建议另外在加一个字段存放去掉html标签,然后对去掉标签的字段做高亮