首页 文章 精选 留言 我的

精选列表

搜索[索引],共10000篇文章
优秀的个人博客,低调大师

考古|以前模板合并到建索引才校验,ES 2.4 提前到创建时,一直在用的写法突然被拒

来源和边界先交代:本文的依据出自 v2.4.6 标签下的官方文件(migrate_2_4.asciidoc、Bootstrap.java、configuration.asciidoc),文中引用的原文均来自这些文件。示例取自官方示例;文末「在 7.17.29 上跑一遍」里的命令与响应取自本机实测。哪些是文档写明、哪些是我的推断,正文里逐处标注。

优秀的个人博客,低调大师

23、 Python快速开发分布式搜索引擎Scrapy精讲—craw母版l创建自动爬虫文件—以及 scrapy item loader机制

转: http://www.bdyss.cn http://www.swpan.cn 用命令创建自动爬虫文件 创建爬虫文件是根据scrapy的母版来创建爬虫文件的 scrapy genspider -l查看scrapy创建爬虫文件可用的母版 Available templates:母版说明 basic 创建基础爬虫文件 crawl 创建自动爬虫文件 csvfeed 创建爬取csv数据爬虫文件 xmlfeed 创建爬取xml数据爬虫文件 创建一个基础母版爬虫,其他同理 scrapy genspider -t 母版名称 爬虫文件名称 要爬取的域名创建一个基础母版爬虫,其他同理如:scrapy genspider -tcrawllagou www.lagou.com 第一步,配置items.py接收数据字段 default_output_processor = TakeFirst()默认利用ItemLoader类,加载items容器类填充数据,是列表类型,可以通过TakeFirst()方法,获取到列表里的内容 input_processor = MapCompose(预处理函数)设置数据字段的预处理函数,可以是多个函数 #-*-coding:utf-8-*- #Defineherethemodelsforyourscrapeditems # #Seedocumentationin: #http://doc.scrapy.org/en/latest/topics/items.html #items.py,文件是专门用于,接收爬虫获取到的数据信息的,就相当于是容器文件 importscrapy fromscrapy.loader.processorsimportMapCompose,TakeFirst fromscrapy.loaderimportItemLoader#导入ItemLoader类也就加载items容器类填充数据 classLagouItemLoader(ItemLoader):#自定义Loader继承ItemLoader类,在爬虫页面调用这个类填充数据到Item类 default_output_processor=TakeFirst()#默认利用ItemLoader类,加载items容器类填充数据,是列表类型,可以通过TakeFirst()方法,获取到列表里的内容 deftianjia(value):#自定义数据预处理函数 return'叫卖录音网'+value#将处理后的数据返给Item classLagouItem(scrapy.Item):#设置爬虫获取到的信息容器类 title=scrapy.Field(#接收爬虫获取到的title信息 input_processor=MapCompose(tianjia),#将数据预处理函数名称传入MapCompose方法里处理,数据预处理函数的形式参数value会自动接收字段title ) 第二步,编写自动爬虫与利用ItemLoader类加载items容器类填充数据 自动爬虫Rule()设置爬虫规则 参数: LinkExtractor()设置url规则 callback='回调函数名称' follow=True 表示在抓取页面继续深入 LinkExtractor()对爬虫获取到的url做规则判断处理 参数: allow= r'jobs/' 是一个正则表达式,表示符合这个url格式的,才提取 deny= r'jobs/' 是一个正则表达式,表示符合这个url格式的,不提取抛弃掉,与allow相反 allow_domains= www.lagou.com/ 表示这个域名下的连接才提取 deny_domains= www.lagou.com/ 表示这个域名下的连接不提取抛弃 restrict_xpaths= xpath表达式 表示可以用xpath表达式限定爬虫只提取一个页面指定区域的URL restrict_css= css选择器,表示可以用css选择器限定爬虫只提取一个页面指定区域的URL tags= 'a' 表示爬虫通过a标签去寻找url,默认已经设置,默认即可 attrs= 'href' 表示获取到a标签的href属性,默认已经设置,默认即可 * 利用自定义Loader类继承ItemLoader类,加载items容器类填充数据 *ItemLoader()实例化一个ItemLoader对象来加载items容器类,填充数据,如果是自定义Loader继承的ItemLoader同样的用法 参数: 第一个参数:要填充数据的items容器类注意加上括号, 第二个参数:response* ItemLoader对象下的方法: add_xpath('字段名称','xpath表达式')方法,用xpath表达式获取数据填充到指定字段 add_css('字段名称','css选择器')方法,用css选择器获取数据填充到指定字段 add_value('字段名称',字符串内容)方法,将指定字符串数据填充到指定字段 load_item()方法无参,将所有数据生成,load_item()方法被yield后数据被填充items容器指定类的各个字段 爬虫文件 #-*-coding:utf-8-*- importscrapy fromscrapy.linkextractorsimportLinkExtractor fromscrapy.spidersimportCrawlSpider,Rule fromadc.itemsimportLagouItem,LagouItemLoader#导入items容器类,和ItemLoader类 classLagouSpider(CrawlSpider):#创建爬虫类 name='lagou'#爬虫名称 allowed_domains=['www.luyin.org']#起始域名 start_urls=['http://www.luyin.org/']#起始url rules=( #配置抓取列表页规则 Rule(LinkExtractor(allow=('ggwa/.*')),follow=True), #配置抓取内容页规则 Rule(LinkExtractor(allow=('post/\d+.html.*')),callback='parse_job',follow=True), ) defparse_job(self,response):#回调函数,注意:因为CrawlS模板的源码创建了parse回调函数,所以切记我们不能创建parse名称的函数 #利用ItemLoader类,加载items容器类填充数据 item_loader=LagouItemLoader(LagouItem(),response=response) item_loader.add_xpath('title','/html/head/title/text()') article_item=item_loader.load_item() yieldarticle_item items.py文件与爬虫文件的原理图 【转载自:http://www.lqkweb.com】

优秀的个人博客,低调大师

ES索引瘦身 压缩——_source _all 均disable filed store为no,引入第三方DB存储原始数据,去掉pos倒排和...

原始数据:835MB ES 设置了_source _all disabled 且设置了仅仅存docs倒排 Wed Feb 22 11:58:27 CST 2017 Before size: 1 /home/bone/elasticsearch-2.4.1/data/ OK, waiting... 0 After size: 435 /home/bone/elasticsearch-2.4.1/data/ Wed Feb 22 11:59:43 CST 2017 done 不做任何压缩: Wed Feb 22 14:56:04 CST 2017 Before size: 1 /home/bone/elasticsearch-2.4.1/data/ OK, waiting... 0 After size: 1656 /home/bone/elasticsearch-2.4.1/data/ Wed Feb 22 14:57:54 CST 2017 done curl -XPOST 'localhost:9200/hec_test3/_forcemerge' bone@PEK1000074003:~/test_data/splunk_es_cmp$ du -sm ~/elasticsearch-2.4.1/data/ 969 /home/bone/elasticsearch-2.4.1/data/ _all disabled: Wed Feb 22 15:22:09 CST 2017 Before size: 1 /home/bone/elasticsearch-2.4.1/data/ OK, waiting... 0 After size: 1576 /home/bone/elasticsearch-2.4.1/data/ Wed Feb 22 15:23:25 CST 2017 done merge后: 787 _source disabled: field store为false 搜索不到东西了 如果不存DB的话 Wed Feb 22 15:26:06 CST 2017 Before size: 1 /home/bone/elasticsearch-2.4.1/data/ OK, waiting... 0 After size: 1288 /home/bone/elasticsearch-2.4.1/data/ Wed Feb 22 15:27:45 CST 2017 done merge后: 512 _source disabled: field store为yes Wed Feb 22 15:33:28 CST 2017 Before size: 1 /home/bone/elasticsearch-2.4.1/data/ OK, waiting... 0 After size: 1583 /home/bone/elasticsearch-2.4.1/data/ Wed Feb 22 15:34:45 CST 2017 done merge后: 780 最终设置: curl -XPUT 'http://localhost:9200/hec_test3' -d ' { "mappings": { "hec_type3": { "_source": { "enabled": false }, "_all": { "enabled": false }, "properties": { "event": { "type": "string", "include_in_all": false, "doc_values": false, "index_options": "docs" } } } } } ' 压缩配置: index.codec: best_compression bash test_es24.sh Wed Feb 22 15:39:39 CST 2017 Before size: 1 /home/bone/elasticsearch-2.4.1/data/ OK, waiting... 0 After size: 892 /home/bone/elasticsearch-2.4.1/data/ Wed Feb 22 15:40:36 CST 2017 done merge后: 202 MB 50个字段拆分后: 用上述最终设置的效果: Wed Feb 22 16:02:59 CST 2017 Before size: 1 /home/bone/elasticsearch-2.4.1/data/ OK, waiting... 0 After size: 1423 /home/bone/elasticsearch-2.4.1/data/ Wed Feb 22 16:05:04 CST 2017 done merge后:686 不做任何配置: Wed Feb 22 16:08:30 CST 2017 Before size: 1 /home/bone/elasticsearch-2.4.1/data/ OK, waiting... 0 After size: 2641 /home/bone/elasticsearch-2.4.1/data/ Wed Feb 22 16:11:54 CST 2017 done merge后: 1650 本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6430378.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

ES里设置索引中倒排列表仅仅存文档ID——采用docs存储后可以降低pos文件和cfs文件大小

index_options Theindex_optionsparameter controls what information is added to the inverted index, for search and highlighting purposes. It accepts the following settings: docs Only the doc number is indexed. Can answer the questionDoes this term exist in this field? freqs Doc number and term frequencies are indexed. Term frequencies are used to score repeated terms higher than single terms. positions Doc number, term frequencies, and term positions (or order) are indexed. Positions can be used forproximity or phrase queries. offsets Doc number, term frequencies, positions, and start and end character offsets (which map the term back to the original string) are indexed. Offsets are used by thepostings highlighter. Analyzedstring fields usepositionsas the default, and all other fields usedocsas the default. PUT my_index { "mappings": { "my_type": { "properties": { "text": { "type": "text", "index_options": "offsets" } } } } } PUT my_index/my_type/1 { "text": "Quick brown fox" } GET my_index/_search { "query": { "match": { "text": "brown fox" } }, "highlight": { "fields": { "text": {} } } } COPY AS CURL VIEW IN CONSOLE Thetextfield will use the postings highlighter by default becauseoffsetsare indexed. 转自:https://www.elastic.co/guide/en/elasticsearch/reference/current/index-options.html 注意:ES2.41里没有text这个type curl -XPUT 'http://localhost:9200/hec_test2' -d ' { "mappings": { "hec_type2": { "properties": { "filed-0": { "type": "string", "index_options": "docs" }, "filed-1": { "type": "string", "index_options": "docs" } } } } } ' 比较测试: 可以比默认的节省10+%的存储空间! 本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6397522.html,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

用户登录
用户注册
修改密码
忘记密码