栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

elasticsearch 索引创建

elasticsearch 索引创建

elasticsearch 索引创建
put data_index
{
    "mappings":{
    "data_index":{
        "properties": {
            "docId": {
              "type": "text"
            },
            "taskId": {
              "type": "text",
              "fielddata" : true
            },
            "title": {
              "type": "text",
              "index":true,
              "analyzer":"ik_smart"
            },
            "summary": {
              "type": "text",
              "index":true,
              "analyzer":"ik_smart"
            },
            "releaseTime": {
              "type": "date",
              "format": "yyyy-MM-dd HH:mm:ss"
            },
            "siteName": {
              "type": "text"
            },
            "siteUrl": {
              "type": "text"
            },
            "siteDetailUrl": {
              "type": "text"
            },
            "content": {
              "type": "text",
              "analyzer":"ik_smart"
            },
            "contentSentenceSplit": {
              "type": "text",
              "analyzer":"ik_smart"
            },
            "md5Code": {
              "type": "keyword"
            },
            "pageId": {
              "type": "text"
            },
            "pointsFavorite": {
              "type": "long"
            },
            "pointsReading": {
              "type": "long"
            },
            "pointsPraise": {
              "type": "long"
            },
            "deleteFlag": {
              "type": "text"
            },
            "userId": {
              "type": "text",
              "fielddata":true
            },
            "monitorSolutionId": {
              "type": "keyword"
            },
            "accountId": {
              "type": "keyword"
            },
            "orgCode": {
              "type": "text"
            },
            "iframeStatus": {
              "type": "text"
            },
            "updateTime": {
              "type": "date",
              "format": "yyyy-MM-dd HH:mm:ss"
            },
            "createTime": {
              "type": "date",
              "format": "yyyy-MM-dd HH:mm:ss"
            }
      }
    }
}
}
说明:

data_index:索引名
data_type:类型

elasticsearch 常用查询
1.查询分词结果

GET /_analyze
{
  "text":"发明专利",
  "analyzer": "ik_max_word"
}

2.词项查询
GET data_index/data_type/_search
{ 
  "_source": {
    "includes": ["praiseType","content"]
  }, 
  "query": {
     "term": {
        "mediaType": {
            "value": "3"
          }
       }
  },
  "from": 0,
  "size": 20
}


3.复合查询

GET data_index/data_type/_search
{ 
  "_source": {
    "includes": ["praiseType","content"]
  }, 
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "mediaType": {
              "value": "3"
            }
          }
        }
      ],
      "must_not":[
        {
          "term": {
            "deleteFlag": {
              "value": "1"
            }
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 20
}

4.聚合

GET data_index/data_type/_search
{ 
  "query": {
     "term": {
        "crawlerType": {
            "value": "1"
          }
       }
  },
  "aggs": {
     "mediaType": {
        "terms": {
            "field": "mediaType"
          }
       }
  },
  "size": 0
}


GET data_index/data_type/_search
{ 
  "aggs": {
     "mediaType": {
        "terms": {
            "field": "mediaType"
          }
       }
  },
  "size": 0
}

查询更新
POST data_index/_update_by_query
{ 
  "script":{
    "source":"ctx._source.praiseType = '2'",
    "lang":"painless"
  },
  "query": {
    "bool": {
      "must_not":[
        {
          "exists": {
            "field":"praiseType"
          }
        }
      ]
    }
  }
}

GET data_index/data_type/_search
{ 
  "_source": {
    "includes": ["praiseType"]
  },
  "script":{
    "inline":"ctx.source.praiseType" = params.praiseType,
    "lang":"painless",
    "params":{"praiseType":"2"}
  },
  "query": {
    "bool": {
      "must":[
        {
          "term": {
            "md5Code":"b42ca83c7eb3e2c4b5c95db90edffc51"
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 20
}


POST twitter/_update_by_query
{
  "script": {
    "source": "ctx._source.likes++",
    "lang": "painless"
  },
  "query": {
    "term": {
      "user": "kimchy"
    }
  }
}

索引别名设置:
POST /_aliases
{
    "actions": [
        { "remove": { "index": "old_index", "alias": "data_index" }},
        { "add":    { "index": "new_index", "alias": "data_index" }}
    ]
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/612820.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号