update数据
def update_dupid_field(_id, key, value, pub_time): """更新es字段数据""" updateBody = { "doc": { key: value, } } status = es.update(index='article_news_' + str(pub_time)[:7], doc_type=doc_type, id=_id, body=updateBody) if status['_shards']['total'] != status['_shards']['successful']: logger.info('update_dupid_field') logger.info(status)
添加子字段
- 路由
my_index/_mapping/
- body
{ "properties": { "risk_cp_score": { "type": "nested", "properties": { "cp_summary": { "type": "text", "analyzer": "qh_analyzer", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } }
- 路由
analyzer和search_analyzer的区别
分析器主要有两种情况会被使用: 第一种是插入文档时,将text类型的字段做分词然后插入倒排索引, 第二种就是在查询时,先对要查询的text类型的输入做分词,再去倒排索引搜索
如果想要让 索引 和 查询 时使用不同的分词器,ElasticSearch也是能支持的,只需要在字段上加上search_analyzer参数
在索引时,只会去看字段有没有定义analyzer,有定义的话就用定义的,没定义就用ES预设的
在查询时,会先去看字段有没有定义search_analyzer,如果没有定义,就去看有没有analyzer,再没有定义,才会去使用ES预设的
{
"properties": {
"sentence": {
"type": "text",
"fields": {
"ngram": {
"type": "text",
"analyzer": "ngram_analyzer",
"search_analyzer": "ngram_analyzer"
}
},
"analyzer": "stopwords_analyzer"
"search_analyzer": "stopwords_analyzer"
}
如果mapping时,同一个字段search_analyzer analyzer一致,索引信息就不显示search_analyzer,默认写入分词和搜索分词是一致的。
- 分析tokenzer
POST my_index/_analyze { "analyzer": "my_analyzer", "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone." }