数据导出elasticdump --input=http://127.0.0.1:9201/mtysj_conference --output=C:\Users\Administrator\Desktop\test_data\es_data\mtysj_conference.json
数据导入elasticdump --input=C:/qbc/baochuan.json --output=http://ip:9200/baochuan_pro
#查看索引配置信息#
GET /mtysj_conference/_settings
#2.插入数据#
POST /user_index/_doc/1
{
“name”:”lisi”,
“address”:”shandong”,
“age”:18,
“interests”:”youyong shufa changge tiaowu”,
“birthday”:”2001-01-19”
}
POST /user_index/_doc/2
{
“name”: “wangwu”,
“address”: “zhejiang”,
“age”: 22,
“interests”: “youyong shufa”,
“birthday”: “1997-01-19”
}
POST /user_index/_doc/3
{
“name”: “zhangsan”,
“address”: “zhejiang”,
“age”: 20,
“interests”: “youyong shufa changge changpao”,
“birthday”: “1999-08-29”
}
POST /user_index/_doc/6
{
“name”: “youyong”,
“address”: “zhejiang”,
“age”: 22,
“interests”: “youyong shufa changge changpao”,
“birthday”: “1999-08-29”
}
#精确查询#
GET /user_index/_search?q=name:youyong
GET /user_index/_search?q=name:youyong&sort=age:desc
#term查询和terms查询:term query去倒排索引中找到确切的term,不知道分词器的存在,适合keyword,date,numetic,是包含(contains操作),不是等值(equals)判断#
GET /user_index/_doc/_search
{
“query”:{
"term":{
"interests":"changpao"
}
}
}
GET /user_index/_doc/_search
{
“query”:{
"terms":{
"interests":["youyong","shufa"]
}
}
}
#查询控制返回的数量#
GET /user_index/_search
{
“from”: 0,
“size”: 2,
“query”: {
"terms": {
"interests": [
"shufa",
"youyong"
]
}
}
}
#返回版本号,版本号是啥???
GET /user_index/_search
{
“version”: true,
“from”: 0,
“size”: 2,
“query”: {
"terms": {
"interests": [
"shufa",
"youyong"
]
}
}
}
#match查询,知道分词器的存在,对filed会进行分词操作,再查询
#单字段查询 match
GET /user_index/_search
{
“query”: {
"match": {
"age": 20
}
}
}
GET /user_index/_search
{
“query”: {
"match": {
"interests": "changge"
}
}
}
#指定多字段查询 multi_match
GET user_index/_search
{
“query”: {
"multi_match": {
"query": "youyong",
"fields": ["interests","name"]
}
}
}
#短语匹配查询
GET /user_index/_search
{
“query”: {
"match_phrase": {
"interests": "shufa changge"
}
}
}
#查询全部
GET /user_index/_search/
{
“query”: {
"match_all": {}
}
}
#指定返回的字段
GET /user_index/_search
{
“_source”: [“name”,”age”],
“query”:{
"match": {
"interests": "changge"
}
}
}
#指定需要的字段,去除不要的字段,可使用通配符
GET /user_index/_search
{
“query”: {
"match_all": {}
},
“_source”: {
"includes": "addr*",
"excludes": ["name","dir*"]
}
}
#排序
#前缀匹配查询,并使用sort排序:desc:降序,asc:升序
GET /user_index/_search
{
“query”: {
"match_phrase_prefix": {
"interests": "you"
}
},
“sort”: [
{
"age": {
"order": "desc"
}
}
]
}
# range范围查询,参数 from,to,include_lower是否包含范围左边界,include_upper是否包含范围右边界,boost
GET /user_index/_search
{
“query”: {
"range": {
"birthday": {
"gte": "1990-10-10",
"lte": "2000-05-01"
}
}
}
}
#wildcard查询,允许通配符 * 和?来查询; * 代表0个或多个字符, ? 代表任意一个字符
GET /user_index/_search
{
“query”: {
"wildcard": {
"name": {
"value": "wang*"
}
}
}
}
# fuzzy 模糊查询,与term查询的模糊等价,是包含(contains)操作,不是等值(equals)操作,不知道分词器的存
GET /user_index/_search
{
“query”: {
"fuzzy": {
"interests": "shuf"
}
}
}
# 删除单个:
DELETE /index
curl -XDELETE http://192.169.1.666:9200/index
#你也可以这样删除多个索引:
DELETE /index_one,index_two
curl -XDELETE http://192.169.1.666:9200/index_one,index_two
DELETE /index_*
curl -XDELETE http://192.169.1.666:9200/index_*
查看全部索引信息
GET _search
{“query”:{“match_all”:{}}}
查看索引库结构
GET mtysj_conference
删除索引库
DELETE mtysj_conference
创建索引库
PUT mtysj_conference
{“settings”:{“index”:{“search”:{“slowlog”:{“level”:”debug”,”threshold”:{“fetch”:{“warn”:”1000ms”,”trace”:”200ms”,”debug”:”800ms”,”info”:”500ms”},”query”:{“warn”:”1000ms”,”trace”:”200ms”,”debug”:”800ms”,”info”:”500ms”}}}},”number_of_shards”:”5”,”max_result_window”:”500000”,”analysis”:{“normalizer”:{“my_normalizer”:{“filter”:[“lowercase”],”type”:”custom”}}},”number_of_replicas”:”1”}}}
创建索引库mapping字段映射
PUT mtysj_conference/_mapping/type
{“properties”:{“addr_city”:{“type”:”text”},”addr_postal_code”:{“type”:”text”,”index”:false,”fields”:{“addr_postal_code”:{“type”:”text”,”index”:false},”addr_postal_code1”:{“type”:”text”,”analyzer”:”standard”}}},”addr_state”:{“type”:”text”,”index”:false},”alt_title”:{“type”:”text”,”fields”:{“alt_title”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”alt_title1”:{“type”:”text”,”analyzer”:”standard”}}},”auhtor_email”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”author”:{“type”:”text”,”fielddata”:true},”author_array”:{“type”:”text”,”fields”:{“author_array”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”author_bio”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”author_email”:{“type”:”text”},”author_telephonenumber”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”author_unit”:{“type”:”text”},”author_unit_address”:{“type”:”text”},”author_unit_address_array”:{“type”:”text”,”fields”:{“author_unit_address_array”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”author_unit_array”:{“type”:”text”,”fields”:{“author_unit_array”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”author_unit_info”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”author_unit_info_array”:{“type”:”text”,”fields”:{“author_unit_info_array”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”batch_number”:{“type”:”keyword”,”fields”:{“batch_number”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”cnpiec_subsid”:{“type”:”text”,”fields”:{“cnpiec_subsid”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”cnpiec_subsid1”:{“type”:”text”}},”analyzer”:”standard”},”conf_acronym”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_addline”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_anth_identifier”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_city”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_country”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_date_end_day”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_date_end_month”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_date_end_year”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_date_start_day”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_date_start_month”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_date_start_year”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_end”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_id”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_identifier”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_info”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_institution”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_loc_addr_line”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_loc_city”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_loc_country”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_loc_state”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_name”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_name_acronym”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_num”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_postcode”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_sponsor”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_start”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_state”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_string_conf”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”conf_theme”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”country”:{“type”:”text”},”create_time”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”create_time_real”:{“type”:”date”,”format”:”yyyy-MM-dd HH:mm:ss SSS||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||yyyy-MM||yyyy”},”create_user”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”doi”:{“type”:”keyword”,”fields”:{“doi”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”eisbn”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”eissn”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”electronic_identifier”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”end_page”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”end_page_real”:{“type”:”integer”},”fulltextpah”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”fund_name”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”graphic_path”:{“type”:”text”,”index”:false},”identifier”:{“type”:”keyword”,”fields”:{“identifier”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”identifier_back”:{“type”:”keyword”},”identifier_unified”:{“type”:”keyword”},”institution”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”is_combine_data”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”is_empty_author”:{“type”:”keyword”},”is_empty_author_email”:{“type”:”keyword”},”is_empty_author_unit”:{“type”:”keyword”},”is_empty_k_abstract”:{“type”:”keyword”},”is_exist_fulltext”:{“type”:”keyword”},”is_exist_pdf”:{“type”:”keyword”,”fields”:{“is_exist_pdf”:{“type”:”keyword”},”is_exist_pdf1”:{“type”:”text”,”analyzer”:”standard”}},”normalizer”:”my_normalizer”},”is_manual_qa”:{“type”:”keyword”,”fields”:{“is_manual_qa”:{“type”:”text”,”analyzer”:”standard”},”is_manual_qa1”:{“type”:”text”,”analyzer”:”standard”}},”normalizer”:”my_normalizer”},”isbn”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”issn”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”journal_abbrev_title”:{“type”:”text”,”fields”:{“journal_abbrev_title”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”journal_abbrev_title1”:{“type”:”text”,”analyzer”:”standard”}}},”journal_identifier”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”journal_md5”:{“type”:”keyword”},”journal_orig_id”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”journal_record_id”:{“type”:”keyword”,”fields”:{“journal_record_id”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”journal_sub_title”:{“type”:”text”,”fields”:{“journal_sub_title”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”journal_sub_title1”:{“type”:”text”,”analyzer”:”standard”}}},”journal_title”:{“type”:”text”,”fields”:{“journal_title”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”journal_trans_title”:{“type”:”text”,”fields”:{“journal_trans_title”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”journal_trans_title1”:{“type”:”text”,”analyzer”:”standard”}}},”k_abstract”:{“type”:”text”},”kwd”:{“type”:”keyword”,”ignore_above”:32765,”normalizer”:”my_normalizer”},”kwd_array”:{“type”:”keyword”,”fields”:{“kwd_array”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”language”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”original_article_id”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”original_journal_id”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”original_journal_record_id”:{“type”:”text”,”fields”:{“original_journal_record_id”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”original_journal_record_id1”:{“type”:”text”}},”analyzer”:”standard”},”other_abstract”:{“type”:”text”},”other_kwd”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”page_num”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”page_num_real”:{“type”:”integer”},”page_range”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”parent_artical_id”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”pdf_path”:{“type”:”keyword”},”period_identifier”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”period_md5”:{“type”:”keyword”},”period_orig_id”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”process_data_state”:{“type”:”text”,”fields”:{“process_data_state”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”process_data_state1”:{“type”:”text”,”analyzer”:”standard”}}},”publish_address”:{“type”:”text”},”publish_time”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”publish_time_real”:{“type”:”date”,”format”:”yyyy-MM-dd HH:mm:ss SSS||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||yyyy-MM||yyyy”},”publish_time_unified”:{“type”:”date”,”format”:”yyyy-MM-dd HH:mm:ss SSS||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||yyyy-MM||yyyy”},”publisher_email”:{“type”:”keyword”},”publisher_uri”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”repeat_target_id”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”source”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”source_title”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”stage”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”standard_data”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”start_page”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”start_page_real”:{“type”:”integer”},”state”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”state_arrival_suppliercode”:{“type”:”keyword”},”state_arrival_timemark”:{“type”:”date”,”format”:”yyyy-MM-dd HH:mm:ss SSS||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||yyyy-MM||yyyy”},”state_combine”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”state_input”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”state_input_repeat”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”state_journal_match”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”state_machine_qa”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”state_manual_qa”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”state_period_standard”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”state_publish”:{“type”:”keyword”},”state_xsd_validate”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”std_issue”:{“type”:”text”,”fields”:{“std_issue”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”std_issue1”:{“type”:”text”,”analyzer”:”standard”}}},”std_period_arrivalno”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”std_period_order”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”std_volume”:{“type”:”text”,”fields”:{“std_volume”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”std_volume1”:{“type”:”text”,”analyzer”:”standard”}}},”std_volume_arrivalno”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”std_volume_order”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”std_year”:{“type”:”keyword”,”fields”:{“std_year”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”std_year1”:{“type”:”text”,”analyzer”:”standard”}}},”sub_title”:{“type”:”text”,”fields”:{“sub_title”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”supplier_code”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”supplier_name”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”time_journal_match”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”time_journal_match_real”:{“type”:”date”,”format”:”yyyy-MM-dd HH:mm:ss SSS||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||yyyy-MM||yyyy”},”title”:{“type”:”text”,”fields”:{“title”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”title_abbrev”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”translated_sub_title”:{“type”:”text”,”fields”:{“translated_sub_title”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”translated_title”:{“type”:”text”,”fields”:{“translated_title”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}},”union_count”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”union_count_real”:{“type”:”integer”},”union_eissn”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”union_id”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”union_issn”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”union_name”:{“type”:”text”,”fields”:{“union_name”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”union_name1”:{“type”:”text”,”analyzer”:”standard”}}},”unique_mark”:{“type”:”keyword”},”update_time”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”update_time_real”:{“type”:”date”,”format”:”yyyy-MM-dd HH:mm:ss SSS||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||yyyy-MM||yyyy”},”update_user”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”volume”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”website_doi”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}},”wos_edition”:{“type”:”keyword”},”xmlContent”:{“type”:”text”,”index”:false},”xmlOrigContent”:{“type”:”text”,”index”:false},”xml_content”:{“type”:”keyword”},”xml_file_name”:{“type”:”keyword”,”normalizer”:”my_normalizer”},”xml_file_path”:{“type”:”keyword”},”xml_orig_content”:{“type”:”text”,”index”:false},”year”:{“type”:”keyword”,”normalizer”:”my_normalizer”}}}
查询全部数据内容
GET mtysj_conference/_search
清空数据,保留结构
POST mtysj_conference/_delete_by_query?pretty=true
{“query”:{“match_all”:{}}}
查看索引索引库信息
GET /_cat/indices?v&pretty
添加索引库mapping字段映射
PUT mtysj_conference/_mapping/type
{“properties”:{“conf_anth_identifier”:{“type”:”text”,”fields”:{“keyword”:{“type”:”keyword”,”ignore_above”:256}}}}}
数据预处理->查看可去重数据
GET /mtysj_conference/_search/
{“size”:10000,”query”:{“bool”:{“filter”:[{“term”:{“batch_number”:{“value”:”WSC2022080904”,”boost”:1}}},{“term”:{“state_xsd_validate”:{“value”:”1”,”boost”:1}}}],”must_not”:[{“term”:{“is_combine_data”:{“value”:”1”,”boost”:1}}}],”adjust_pure_negative”:true,”boost”:1}},”_source”:{“includes”:[“unique_mark”,”original_article_id”,”identifier”,”batch_number”,”state_xsd_validate”],”excludes”:[]},”sort”:[{“create_time_real”:{“order”:”asc”}},{“_id”:{“order”:”asc”}}]}
数据预处理->查询xml3.0可校验数据
GET /mtysj_conference/_search/
{“size”:10000,”query”:{“bool”:{“filter”:[{“term”:{“batch_number”:{“value”:”WSC2022080904”,”boost”:1}}}],”must_not”:[{“term”:{“is_combine_data”:{“value”:”1”,”boost”:1}}}],”adjust_pure_negative”:true,”boost”:1}},”_source”:{“includes”:[“xml_content”],”excludes”:[]},”sort”:[{“_id”:{“order”:”asc”}}]}
数据预处理->查询可析出数据
GET /mtysj_conference/_search/
{“size”:10000,”query”:{“bool”:{“must”:[{“term”:{“state_manual_qa”:{“value”:”2”,”boost”:1.0}}}],”must_not”:[{“term”:{“is_combine_data”:{“value”:”1”,”boost”:1.0}}},{“exists”:{“field”:”journal_orig_id”,”boost”:1.0}}],”adjust_pure_negative”:true,”boost”:1.0}},”_source”:{“includes”:[“batch_number”,”journal_title”,”issn”,”eissn”,”isbn”,”eisbn”,”title”,”year”,”identifier”,”conf_anth_identifier”,”conf_identifier”,”source_title”,”conf_id”,”conf_name”,”conf_sponsor”,”conf_theme”,”conf_date_start_year”,”conf_date_start_month”,”conf_date_start_day”,”conf_date_end_year”,”conf_date_end_month”,”conf_date_end_day”,”conf_name”,”conf_sponsor”,”conf_loc_state”,”conf_loc_city”,”conf_loc_country”,”conf_loc_addr_line”,”conf_end”,”conf_start”,”create_time”,”update_time”,”conf_name_acronym”],”excludes”:[]},”sort”:[{“create_time”:{“order”:”asc”}},{“_id”:{“order”:”asc”}}]}
查询language为null的数据
GET /mtysj_article/_search
{
“_source”: [“id”,”language”],
“query”: {
“bool”: {
“must_not”: {
“exists”: {
“field”: “language”
}
}
}
}}
es 按条件查询数据总条数
//请求地址
post
http://eshost:9200/esindex-20220502/_search?
//查询条件:
{
“query”: {
“bool”: {
“must”: [{
“term”: {
“trace_type.keyword”: “xxxxxx”
}
}, {
“term”: {
“product_type.keyword”: “aaaaa”
}
}],
“must_not”: [],
“should”: []
}
},
“from”: 0,
“size”: 0,
“sort”: [],
“track_total_hits”:true,//开启精确查询,没有此字段,total最大10000条
“aggs”: {}
}
查询supplier_code值为OpenAccess,language不为null不为””的数据
GET /mtysj_article/_search
{
“query”:{
“bool”:{
“must”:[
{
“match”:{
“supplier_code”:”OpenAccess”
}
}
],
“filter”:{
“exists”:{
“field”:”language”
}
},
“must_not”:[
{
“match”:{
“language”:””
}
}
]
}
},
“from”:0,
“size”:5000,
“sort”:[
],
"aggs":{
}
}
查询supplier_code为wos的,fund_name不为null,fund_name不为’’的数据
GET /mtysj_article/_search
{
“query”:{
“bool”:{
“must”:[
{
“match”:{
“supplier_code”:”wos”
}
}
],
“must_not”:[
{
“match”:{
“original_article_id”:””
}
}
],
“filter”:{
“exists”:{
“field”:”original_article_id”
}
}
}
},
"track_total_hits":true
}
更新
覆盖式更新
会把旧数据替换掉
PUT student-001/_doc/1?refresh=true
{
“id”: 1,
“name”: “student-1”,
“year”: 1
}
部分更新
把 id 为1的数据的 name 字段更新
POST student-001/_update/1?refresh=true
{
“doc”: {
“name”: “student-123”
}
}
如果数据不存在,则作为新数据添加;如果数据已经存在,则更新旧数据。那么我们可以添加参数 doc_as_upsert
POST student-001/_update/1?refresh=true
{
"doc": {
"name": "student-23"
},
"doc_as_upsert": true
}
脚本更新
更新journal_orig_id和conf_anth_identifier为null值
POST mtysj_conference/_update_by_query
{
“script”: {
“source”: “ctx._source.journal_orig_id=null;ctx._source.conf_anth_identifier=null”
}
}
POST mtysj_conference/_update_by_query
{
“script”: {
“source”: “ctx._source.journal_orig_id=null”,
“lang”: “painless”
},
“query”: {
"term": {
"user": "kimchy"
}
}
}
查询某个字段重复数据个数
GET /mtysj_conference/_search/
{
“size”:0,
“aggs”:{
“grade_dictinct_count”:{
“cardinality”:{
“field”:”anth_md”
}
}
}
}