关键词:索引查询,记录查询及删除,防冗余重建索引
一、ES修改索引dzplib使其规范化
1.1 查一个索引
curl -XGET localhost:9200/_all?pretty-----全部索引详细信息查询
curl -XGET localhost:9200/dzplib?pretty-----单个全部查询
curl -XGET localhost:9200/dzplib/_settings?pretty-----单个settings查询
curl -XGET localhost:9200/dzplib/_mapping?pretty-----单个mapping查询
1.2 查mongo中一条数据
db.Problem.find().limit(1) ----------------返回第一条记录
db.Problem.find().limit(2) -----------------返回前两条记录
1.3 删除mongo中一条数据
db.Problem.remove({"comments":"test_qhz"})
1.4 一道题的格式化
1)一级关键词有42个,二级关键词有7个。
{
"origDocID":"393558",--------------------------------------------------------1
"origSubjID": "161",----------------------------------------------------------2
"subject": "高中数学理",------------------------------------------------------3
"origKeyID":"110355",--------------------------------------------------------4
"key": "平面向量的概念及线性运算",--------------------------------------------5
"origKeyCascadeID":"91511_110300_110355",------------------------------------6
"keyCascade": "高中数学理~平面向量~平面向量的概念及线性运算",-----------------7
"origDifficultyID":"82704",--------------------------------------------------8
"difficulty": "低",-----------------------------------------------------------9
"origTypeID":"112297",------------------------------------------------------10
"type": "解答题",------------------------------------------------------------11
"origLevelID":"0",----------------------------------------------------------12
"level":"",-----------------------------------------------------------------13
"origTeachID":"112202",-----------------------------------------------------14
"teach": "2.2.1 向量加法运算及其几何意义",-----------------------------------15
"origTeachCascadeID":"96578_101693_101736_101744_101746_112202",------------16
"teachCascade": "高中数学~人教课标A版~必修4~第二章 平面向量~2.2 平面向量的线性运算~2.2.1 向量加法运算及其几何意义",--------------------------------------17
"origProvinceID":"112393",--------------------------------------------------18
"province": "全国",----------------------------------------------------------19
"gradeID":"110266",---------------------------------------------------------20
"grade": "必修4",-----------------------------------------------------------21
"origYearID":"",------------------------------------------------------------22
"year":"2015",--------------------------------------------------------------23
"anwserTime":"0",-----------------------------------------------------------24
"origQualityID":"82717",----------------------------------------------------25
"quality": "优",-------------------------------------------------------------26
"origApplyID": "0",----------------------------------------------------------27
"apply":"",-----------------------------------------------------------------28
"text": "三个向量首尾相接且其和为零向量则三个向量一定构成三角形吗?1137089",--29
"origSourceTypeID":"110235",------------------------------------------------30
"sourceType": "同步测验",----------------------------------------------------31
"score":"0.0",--------------------------------------------------------------32
"comments":"",--------------------------------------------------------------33
"subQstNum":"0",------------------------------------------------------------34
"content":[-----------------------------------------------------------------35
{
"tqID":"393558",----------------------------------------------------------35-1
"outputIMG":"false",------------------------------------------------------35-2
"parentID":"",------------------------------------------------------------35-3
"docLibID":"1",-----------------------------------------------------------35-4
"docID": "393558",---------------------------------------------------------35-5
"elementName":"题目",-----------------------------------------------------35-6
"elementContent":"<XHTML xmlns:mml=\"http://www.w3.org/1998/Math/MathML\">三个向量首尾相接且其和为零向量,则三个向量一定构成三角形吗?</XHTML>"------------35-7
},
{
"parentID":"393558",
"elementName":"答案",
"elementContent":"<XHTML xmlns:mml=\"http://www.w3.org/1998/Math/MathML\">不一定,当三个向量两两不共线时,才构成三角形<i>.</i></XHTML>",
"tqID":"393558_X0",
"outputIMG":"false"
}
],
"createdAt": "Fri Nov 06 2015 16:27:47 GMT+0800(CST)",--------------------- 36
"lastModifiedAt": "Fri Nov 06 201516:27:47 GMT+0800 (CST)",---------------- 37
"lastModifiedBy":"0",-------------------------------------------------------38
"createdUserID": "dz101",----------------------------------------------------39
"isPublic":"1",-------------------------------------------------------------40
"isMark":"1",---------------------------------------------------------------41
"isVisible": 1---------------------------------------------------------------42
}
2)简化版本如下:
{
"origDocID":"393558",--------------------------------------------------------1
"origSubjID":"161",----------------------------------------------------------2
"subject": "高中数学理",------------------------------------------------------3
"origKeyID":"110355",--------------------------------------------------------4
"key": "平面向量的概念及线性运算",--------------------------------------------5
"origKeyCascadeID":"91511_110300_110355",------------------------------------6
"keyCascade": "高中数学理~平面向量~平面向量的概念及线性运算",-----------------7
"origDifficultyID":"82704",--------------------------------------------------8
"difficulty": "低",-----------------------------------------------------------9
"origTypeID":"112297",------------------------------------------------------10
"type": "解答题",------------------------------------------------------------11
"origLevelID":"0",----------------------------------------------------------12
"level": "",-----------------------------------------------------------------13
"origTeachID":"112202",-----------------------------------------------------14
"teach": "2.2.1 向量加法运算及其几何意义",-----------------------------------15
"origTeachCascadeID":"96578_101693_101736_101744_101746_112202",------------16
"teachCascade": "高中数学~人教课标A版~必修4~第二章 平面向量~2.2 平面向量的线性运算~2.2.1 向量加法运算及其几何意义",--------------------------------------17
"origProvinceID":"112393",--------------------------------------------------18
"province": "全国",----------------------------------------------------------19
"gradeID":"110266",---------------------------------------------------------20
"grade": "必修4",-----------------------------------------------------------21
"origYearID": "",------------------------------------------------------------22
"year":"2015",--------------------------------------------------------------23
"anwserTime":"0",-----------------------------------------------------------24
"origQualityID":"82717",----------------------------------------------------25
"quality": "优",-------------------------------------------------------------26
"origApplyID":"0",----------------------------------------------------------27
"apply":"",-----------------------------------------------------------------28
"text": "三个向量首尾相接且其和为零向量则三个向量一定构成三角形吗?1137089",--29-------------需要ik--1
"origSourceTypeID":"110235",------------------------------------------------30
"sourceType": "同步测验",----------------------------------------------------31
"score": "0.0",--------------------------------------------------------------32
"comments":"",--------------------------------------------------------------33
"subQstNum":"0",------------------------------------------------------------34
"content": [-----------------------------------------------------------------35
{
"tqID":"393558",----------------------------------------------------------35-1
"outputIMG":"false",------------------------------------------------------35-2
"parentID":"",------------------------------------------------------------35-3
"docLibID":"1",-----------------------------------------------------------35-4
"docID":"393558",---------------------------------------------------------35-5
"elementName":"题目",-----------------------------------------------------35-6
"elementContent":"<XHTML xmlns:mml=\"http://www.w3.org/1998/Math/MathML\">三个向量首尾相接且其和为零向量,则三个向量一定构成三角形吗?</XHTML>"------------35-7------------------需要ik--2
},
{
"parentID":"393558",
"elementName":"答案",
"elementContent":"<XHTML xmlns:mml=\"http://www.w3.org/1998/Math/MathML\">不一定,当三个向量两两不共线时,才构成三角形<i>.</i></XHTML>",
"tqID":"393558_X0",
"outputIMG":"false"
}
],
"createdAt": "Fri Nov 06 2015 16:27:47GMT+0800 (CST)",--------------------- 36
"lastModifiedAt": "Fri Nov 06 201516:27:47 GMT+0800 (CST)",---------------- 37
"lastModifiedBy":"0",-------------------------------------------------------38
"createdUserID":"dz101",----------------------------------------------------39
"isPublic":"1",-------------------------------------------------------------40
"isMark":"1",---------------------------------------------------------------41
"isVisible":1---------------------------------------------------------------42
}
3)使用head
http://192.168.1.15:9200/_plugin/head/
注: 这个页面可以看到详细信息,比如索引,比如集群。
4)现在建立的索引
a.)之前过程
现在建立索引的过程是,先删除数据库dzplib,之后,新建数据库dzplib,向里面插入一条数据(字段不涉及到ik分词),同步到Es后,更新索引,加上ik分词,再之后,把备份的数据库dzplib恢复过来,同步到ES之后,就丰富了索引,并且不会冲掉ik分词。
b.)之前过程存在的问题
之前过程存在问题,具体为:它会产生一些冗余信息,降低了索引效率。改进办法是:我开始建索引时,就把全部字段放进去,并且注明禁止动态同步字段过来。这样,就保证了索引不会变,就是不知道数据库中的数据还会不会过来。如果能过来,则就在功告成了。
c.)新过程(不动态更新同步过来的数据建立索引索引----------------防止冗余)
具体步骤为:
第一步:删除数据库dzplib(如果有试题更新,最好先备份一下)
show dbs;
use dzplib
db.dropDatabase();
第二步:建立索引
curl -XPOST 'http://localhost:9200/dzplib'
第三步:更新索引
分别更新Paper及Problem,如下:
更新Paper:
注:这两个更新里面都加入了防止动态更新。其中Paper中加了三处"dynamic":"false",而Problem中加了两处"dynamic":"false",其实按理说,每个父节点中加了就成,子字段中不用加了,下次试试,应该能行。
第三步:恢复数据库
sudo mongorestore -h 127.0.0.1 -ddzplib /opt/DataBase/dzplib/
d.)发现数据是能过来的,如下:
看下索引是否产生冗余:---答案是没产生
注:因为在更新索引时,加入了防止动态更新代码,ik分词也没有被新同步的mongoDB上的数据冲掉,完美!