Elasticsearch Java????????????
???????????? ???????[ 2014/2/13 9:29:09 ] ???????????????? Java ?????
????????mapping
???????????????mapping?????????????????
{
"page":{
"properties":{
"title":{
"type":"string"??
"indexAnalyzer":"ik"??
"searchAnalyzer":"ik"
}??
"content":{
"type":"string"??
"indexAnalyzer":"ik"??
"searchAnalyzer":"ik"
}
}
}
}
????indexAnalyzer????????????????searchAnalyzer????????????????
????java mapping???????£?
XContentBuilder content = XContentFactory.jsonBuilder().startObject()
.startObject("page")
.startObject("properties")
.startObject("title")
.field("type"?? "string")
.field("indexAnalyzer"?? "ik")
.field("searchAnalyzer"?? "ik")
.endObject()
.startObject("code")
.field("type"?? "string")
.field("indexAnalyzer"?? "ik")
.field("searchAnalyzer"?? "ik")
.endObject()
.endObject()
.endObject()
.endObject()
????????????????????????????????????з???
????????
????ik?????????????https://github.com/medcl/elasticsearch-analysis-ik
????mmseg?????????????https://github.com/medcl/elasticsearch-analysis-mmseg
????????????????鷳???????????????ú??es?汾????????£?https://github.com/medcl/elasticsearch-rtf
????elasticsearch??????÷?
??????????
????1. ?????? database?? ?? index
????2. ?????? table?? ?? tag
????3. ??????browser?? ???curl?????п???????. ???????? java heap ooxx...
????curl: -X ????? RESTful ?? GET?? POST ...
????-d ?????????? (d = data to send)
????1. create:
??????? ID ???????????? ??ò??PUT?? POST???????
????$ curl -XPOST localhost:9200/films/md/2 -d '
????{ "name":"hei yi ren"?? "tag": "good"}'
??????????????? ID ??????????
????$ curl -XPOST localhost:9200/films/md -d '
????{ "name":"ma da jia si jia3"?? "tag": "good"}'
????2. ?????
????2.1 ??????е? index?? type:
????$ curl localhost:9200/_search?pretty=true
????2.2 ??????index?????е?type:
????$ curl localhost:9200/films/_search
????2.3 ??????index ?£? ??? type?????е?????
????$ curl localhost:9200/films/md/_search?pretty=true
????2.4 ???в?????????
????$ curl localhost:9200/films/md/_search?q=tag:good
????{"took":7??"timed_out":false??"_shards":{"total":5??"successful":5??"failed":0}??"hits":{"total":2??"max_score":1.0??"hits":[{"_index":"film"??"_type":"md"??"_id":"2"??"_score":1.0?? "_source" :
????{ "name":"hei yi ren"?? "tag": "good"}}??{"_index":"film"??"_type":"md"??"_id":"1"??"_score":0.30685282?? "_source" :
????{ "name":"ma da jia si jia"?? "tag": "good"}}]}}
????2.5 ???JSON?????????? ????? query ?? term ??????
????$ curl localhost:9200/film/_search -d '
????{"query" : { "term": { "tag":"bad"}}}'
????3. update
????$ curl -XPUT localhost:9200/films/md/1 -d { ...(data)... }
????4. ????? ??????е??
????$ curl -XDELETE localhost:9200/films
?????????
????????????????????Java6??Mustang??????2006????Щ?????????????????????????????????У?????????????????????????????????????Java7(Dolphin)?????
??????????????д????????ElasticSearch??????Java6??7?????????????
????Elasticsearch??Java??????????????????á????????£??????Щ???????????????????????????????????????????????ElasticSearch??
????????????????ElasticSearch?????????????????????Щ???á???Щ??????????????????
????????????????Elasticsearch?????????????????????????????????????????Щ??????????????
????Elasticsearch JVM ?????????
??????Щ??Elasticsearch 0.19.11?汾????????á?
????JVM???? Elasticsearch???? Environment????
-Xms 256m ES_MIN_MEM
-Xmx 1g ES_MAX_MEM
-Xms and -Xmx ES_HEAP_SIZE
-Xmn ES_HEAP_NEWSIZE
-XX:MaxDirectMemorySize ES_DIRECT_SIZE
-Xss 256k
-XX:UseParNewGC +
-XX:UseConcMarkSweepGC +
-XX:CMSInitiatingOccupancyFraction 75
-XX:UseCMSInitiatingOccupancyOnly +
-XX:UseCondCardMark (commented out)
??????????????????Elasticsearch?????256M??1GB?????檔
???????????????????????????????????????????????????а????????./bin/elasticsearch -f?????Elasticsearch??????????????????????????????????????????????????????????????????????Elasticsearch????????????????????2GB RAM??????????檔
????ES_MIN_MEM/ES_MAX_MEM???????С?????á??μ?ES_HEAP_SIZE?????????????????????????????????С??????????????????????????????????????????????????????????????????????????
????ES_HEAP_NEWSIZE???????????????????????С??????????????С??
????ES_DIRECT_SIZE??????????????С????JVM????NIO??????????????????С?????????????????????????????????????64λ??????????Ч???????????????????塣Elasticsearch??????????????????(???????OOM)??
??????????????Java??????ж???????????????????????μ?JVM????????????
JVM parameter Garbage collector
-XX:+UseSerialGC serial collector
-XX:+UseParallelGC parallel collector
-XX:+UseParallelOldGC Parallel compacting collector
-XX:+UseConcMarkSweepGC Concurrent-Mark-Sweep (CMS) collector
-XX:+UseG1GC Garbage-First collector (G1)
????UseParNewGC??UseConcMarkSweepGC??????????????????????????????UseConcMarkSweepGC??????UseParNewGC??????????????????Serial collector??????Java6??????????????
????CMSInitiatingOccupancyFraction?????????CMS??Concurrent-Mark-Sweep??????????????????????????????????????????75.?????????С????С???????????С???????JVM?????????75%???????????????????????????????С???????????????GC??
????UseCondCardMark???????????????card table????????marking?????ж?????ж???????????store??????UseCondCardMark?????Garbage-First?????????????????????????????????????????card table marking???????????????μ????????????????????????ElasticSearch?У?????????????????
??????Щ???????ο?????Apache Cassandra???????????JVM?????????????
????????????ElastciSearch???????????
????1. ?????????????????????????С????????1GB
????2.????????????????????????罫gc???75%???С?????????????????????????
????3.????Java7????G1???????????????ElasticSearch????Java7u4?????汾???
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11