当前位置: 首页 > news >正文

佛山网站建设网络公司软文世界官网

佛山网站建设网络公司,软文世界官网,自适应网站什么意思,更新wordpress咋办Prefix queries 被用于在查询时返回在提供的字段中包含特定前缀的文档。有时我们可能想使用前缀查询单词,例如 Leonardo 的 Leo 或 Marlon Brando、Mark Hamill 或 Martin Balsam 的 Mar。 Elasticsearch 提供了一个前缀查询,用于获取匹配单词开头部分&a…

Prefix queries 被用于在查询时返回在提供的字段中包含特定前缀的文档。有时我们可能想使用前缀查询单词,例如 Leonardo 的 Leo 或 Marlon Brando、Mark Hamill 或 Martin Balsam 的 Mar。 Elasticsearch 提供了一个前缀查询,用于获取匹配单词开头部分(前缀)的记录。 

准备数据

示例

我们先准备数据。我们想创建如下的一个 movies 的索引:

PUT movies
{"settings": {"analysis": {"analyzer": {"en_analyzer": {"tokenizer": "standard","filter": ["lowercase","stop"]},"shingle_analyzer": {"type": "custom","tokenizer": "standard","filter": ["lowercase","shingle_filter"]}},"filter": {"shingle_filter": {"type": "shingle","min_shingle_size": 2,"max_shingle_size": 3}}}},"mappings": {"properties": {"title": {"type": "text","analyzer": "en_analyzer","fields": {"suggest": {"type": "text","analyzer": "shingle_analyzer"}}},"actors": {"type": "text","analyzer": "en_analyzer","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"description": {"type": "text","analyzer": "en_analyzer","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"director": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"genre": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"metascore": {"type": "long"},"rating": {"type": "float"},"revenue": {"type": "float"},"runtime": {"type": "long"},"votes": {"type": "long"},"year": {"type": "long"},"title_suggest": {"type": "completion","analyzer": "simple","preserve_separators": true,"preserve_position_increments": true,"max_input_length": 50}}}
}

我们接下来使用 _bulk 命令来写入一些文档到这个索引中去。我们使用这个链接中的内容。我们使用如下的方法:

POST movies/_bulk
{"index": {}}
{"title": "Guardians of the Galaxy", "genre": "Action,Adventure,Sci-Fi", "director": "James Gunn", "actors": "Chris Pratt, Vin Diesel, Bradley Cooper, Zoe Saldana", "description": "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.", "year": 2014, "runtime": 121, "rating": 8.1, "votes": 757074, "revenue": 333.13, "metascore": 76}
{"index": {}}
{"title": "Prometheus", "genre": "Adventure,Mystery,Sci-Fi", "director": "Ridley Scott", "actors": "Noomi Rapace, Logan Marshall-Green, Michael Fassbender, Charlize Theron", "description": "Following clues to the origin of mankind, a team finds a structure on a distant moon, but they soon realize they are not alone.", "year": 2012, "runtime": 124, "rating": 7, "votes": 485820, "revenue": 126.46, "metascore": 65}....

在上面,为了说明的方便,我省去了其它的文档。你需要把整个 movies.txt 的文件拷贝过来,并全部写入到 Elasticsearch 中。它共有1000 个文档。

Prefix 查询

我们使用如下的例子来进行查询:

GET movies/_search?filter_path=**.hits
{"_source": false, "fields": ["actors"], "query": {"prefix": {"actors.keyword": {"value": "Mar"}}}
}

当我们搜索前缀 Mar 时,上面的查询获取了演员以 Mar 开头的电影。请注意,我们正在 actors.keyword 字段上运行前缀查询。它是一个 keyword 字段。返回的结果为:

{"hits": {"hits": [{"_index": "movies","_id": "RgJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"actors": ["Mark Wahlberg, Michelle Monaghan, J.K. Simmons, John Goodman"]}},{"_index": "movies","_id": "SQJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"actors": ["Mark Wahlberg, Kurt Russell, Douglas M. Griffin, James DuMont"]}},{"_index": "movies","_id": "awJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"actors": ["Mario Casas, Ana Wagener, José Coronado, Bárbara Lennie"]}},{"_index": "movies","_id": "ggJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"actors": ["Mark Wahlberg, Nicola Peltz, Jack Reynor, Stanley Tucci"]}},{"_index": "movies","_id": "mgJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"actors": ["Mark Rylance, Ruby Barnhill, Penelope Wilton,Jemaine Clement"]}},{"_index": "movies","_id": "xAJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"actors": ["Mark Ruffalo, Michael Keaton, Rachel McAdams, Liev Schreiber"]}},{"_index": "movies","_id": "3gJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"actors": ["Mark Huberman, Susan Loughnane, Steve Oram,Catherine Walker"]}},{"_index": "movies","_id": "EwJfWIYBfOmyc7Qq5giX","_score": 1,"fields": {"actors": ["Martin Freeman, Ian McKellen, Richard Armitage,Andy Serkis"]}},{"_index": "movies","_id": "MQJfWIYBfOmyc7Qq5giX","_score": 1,"fields": {"actors": ["Mark Wahlberg, Taylor Kitsch, Emile Hirsch, Ben Foster"]}},{"_index": "movies","_id": "tgJfWIYBfOmyc7Qq5giY","_score": 1,"fields": {"actors": ["Marilyn Manson, Mark Boone Junior, Sam Quartin, Niko Nicotera"]}}]}
}

很显然,actors 的列表中都是以 Mar 为开头的列表。

注意前缀查询是一个昂贵的查询 - 有时会破坏集群的稳定性。

我们不需要在字段块级别添加由 value 组成的对象。 相反,你可以创建一个缩短的版本,如下所示,为简洁起见:

GET movies/_search?filter_path=**.hits
{"_source": false,"fields": ["actors"],"query": {"prefix": {"actors.keyword": "Mar"}}
}

由于我们希望在结果中找出匹配的字段,因此我们将通过在查询中添加高亮来突出显示结果。 我们向前缀查询添加一个 highlight 显示块。 这会突出一个或多个匹配的字段,如下面的清单所示。

GET movies/_search?filter_path=**.hits
{"_source": false,"query": {"prefix": {"actors.keyword": "Mar"}},"highlight": {"fields": {"actors.keyword": {}}}
}

上面的搜索结果显示:

{"hits": {"hits": [{"_index": "movies","_id": "RgJfWIYBfOmyc7Qq5geX","_score": 1,"highlight": {"actors.keyword": ["<em>Mark Wahlberg, Michelle Monaghan, J.K. Simmons, John Goodman</em>"]}},{"_index": "movies","_id": "SQJfWIYBfOmyc7Qq5geX","_score": 1,"highlight": {"actors.keyword": ["<em>Mark Wahlberg, Kurt Russell, Douglas M. Griffin, James DuMont</em>"]}},{"_index": "movies","_id": "awJfWIYBfOmyc7Qq5geX","_score": 1,"highlight": {"actors.keyword": ["<em>Mario Casas, Ana Wagener, José Coronado, Bárbara Lennie</em>"]}},{"_index": "movies","_id": "ggJfWIYBfOmyc7Qq5geX","_score": 1,"highlight": {"actors.keyword": ["<em>Mark Wahlberg, Nicola Peltz, Jack Reynor, Stanley Tucci</em>"]}},{"_index": "movies","_id": "mgJfWIYBfOmyc7Qq5geX","_score": 1,"highlight": {"actors.keyword": ["<em>Mark Rylance, Ruby Barnhill, Penelope Wilton,Jemaine Clement</em>"]}},{"_index": "movies","_id": "xAJfWIYBfOmyc7Qq5geX","_score": 1,"highlight": {"actors.keyword": ["<em>Mark Ruffalo, Michael Keaton, Rachel McAdams, Liev Schreiber</em>"]}},{"_index": "movies","_id": "3gJfWIYBfOmyc7Qq5geX","_score": 1,"highlight": {"actors.keyword": ["<em>Mark Huberman, Susan Loughnane, Steve Oram,Catherine Walker</em>"]}},{"_index": "movies","_id": "EwJfWIYBfOmyc7Qq5giX","_score": 1,"highlight": {"actors.keyword": ["<em>Martin Freeman, Ian McKellen, Richard Armitage,Andy Serkis</em>"]}},{"_index": "movies","_id": "MQJfWIYBfOmyc7Qq5giX","_score": 1,"highlight": {"actors.keyword": ["<em>Mark Wahlberg, Taylor Kitsch, Emile Hirsch, Ben Foster</em>"]}},{"_index": "movies","_id": "tgJfWIYBfOmyc7Qq5giY","_score": 1,"highlight": {"actors.keyword": ["<em>Marilyn Manson, Mark Boone Junior, Sam Quartin, Niko Nicotera</em>"]}}]}
}

我们之前讨论过,前缀查询在运行查询时会施加额外的计算压力。 幸运的是,有一种方法可以加快这种煞费苦心的性能不佳的前缀查询 —— 将在下一节中讨论。

加速前缀查询

这是因为引擎必须根据前缀(任何带字母的单词)得出结果。 因此,前缀查询运行起来很慢,但有一种机制可以加快它们的速度:在字段上使用 index_prefixes 参数。

我们可以在开发映射模式时在字段上设置 index_prefixes 参数。 例如,下面清单中的映射定义在我们为本练习创建的新索引 new_movies 上使用附加参数 index_prefixes 设置 title 字段(请记住,title 字段是 text 数据类型)。我们按照如下的命令来创建这个新索引:

PUT new_movies
{"settings": {"analysis": {"analyzer": {"en_analyzer": {"tokenizer": "standard","filter": ["lowercase","stop"]},"shingle_analyzer": {"type": "custom","tokenizer": "standard","filter": ["lowercase","shingle_filter"]}},"filter": {"shingle_filter": {"type": "shingle","min_shingle_size": 2,"max_shingle_size": 3}}}},"mappings": {"properties": {"title": {"type": "text","index_prefixes": {}},"actors": {"type": "text","analyzer": "en_analyzer","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"description": {"type": "text","analyzer": "en_analyzer","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"director": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"genre": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"metascore": {"type": "long"},"rating": {"type": "float"},"revenue": {"type": "float"},"runtime": {"type": "long"},"votes": {"type": "long"},"year": {"type": "long"},"title_suggest": {"type": "completion","analyzer": "simple","preserve_separators": true,"preserve_position_increments": true,"max_input_length": 50}}}
}

在上面,我们为 new_movies 添加了如下的 index_prefixes 相:

      "title": {"type": "text","index_prefixes": {},"analyzer": "en_analyzer","fields": {"suggest": {"type": "text","analyzer": "shingle_analyzer"}}}

从清单中的代码可以看出,title 属性包含一个附加属性 index_prefixes。 这向引擎表明,在索引过程中,它应该创建带有预置前缀的字段并存储这些值。 我们使用如下的代码来写入数据到这个索引中:

POST _reindex
{"source": {"index": "movies"},"dest": {"index": "new_movies"}
}

我们使用 reindex 把之前的 movies 里的文档写入到 new_movies 索引中去。

因为我们在上面显示的列表中的 title 字段上设置了 index_prefixes,所以 Elasticsearch 默认为最小字符大小 2 和最大字符大小 5 索引前缀。 这样,当我们运行前缀查询时,就不需要计算前缀了。 相反,它从存储中获取它们。

当然,我们可以更改 Elasticsearch 在索引期间尝试为我们创建的前缀的默认最小和最大大小。 这是通过调整 index_prefixes 对象的大小来完成的,如下面的清单所示。

PUT my-index-000001
{"mappings": {"properties": {"full_name": {"type": "text","index_prefixes": {"min_chars" : 1,"max_chars" : 10}}}}
}

在清单中,我们要求引擎预先创建最小和最大字符长度分别为 4 个和 10 个字母的前缀。 注意,min_chars 必须大于 0,max_chars 应小于 20 个字符。 这样,我们就可以在索引过程中自定义 Elasticsearch 应该预先创建的前缀。

我们接着可以对 title 字段做类似下面的搜索:

GET new_movies/_search?filter_path=**.hits
{"_source": false,"fields": ["title"], "query": {"prefix": {"title": {"value": "ga"}}}
}

在上面的搜索中,我们查询 titile 字段里 含有 ga 为开头的文档。上述搜索返回如下的结果:

{"hits": {"hits": [{"_index": "new_movies","_id": "BAJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"title": ["Guardians of the Galaxy"]}},{"_index": "new_movies","_id": "jQJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"title": ["The Great Gatsby"]}},{"_index": "new_movies","_id": "lQJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"title": ["Ah-ga-ssi"]}},{"_index": "new_movies","_id": "mwJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"title": ["The Hunger Games"]}},{"_index": "new_movies","_id": "sAJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"title": ["Beyond the Gates"]}},{"_index": "new_movies","_id": "ygJfWIYBfOmyc7Qq5geX","_score": 1,"fields": {"title": ["The Imitation Game"]}},{"_index": "new_movies","_id": "jQJfWIYBfOmyc7Qq5giY","_score": 1,"fields": {"title": ["Whisky Galore"]}},{"_index": "new_movies","_id": "nAJfWIYBfOmyc7Qq5giY","_score": 1,"fields": {"title": ["The Hunger Games: Mockingjay - Part 2"]}},{"_index": "new_movies","_id": "1QJfWIYBfOmyc7Qq5giY","_score": 1,"fields": {"title": ["Sherlock Holmes: A Game of Shadows"]}},{"_index": "new_movies","_id": "2gJfWIYBfOmyc7Qq5giY","_score": 1,"fields": {"title": ["American Gangster"]}}]}
}

很显然,返回的结果里都含有 "ga" 为开头的单词。


文章转载自:
http://dinncotussle.bpmz.cn
http://dinncochordoma.bpmz.cn
http://dinncoreverse.bpmz.cn
http://dinncoprophetess.bpmz.cn
http://dinncomsph.bpmz.cn
http://dinncohonorand.bpmz.cn
http://dinncorecoal.bpmz.cn
http://dinncophytopathogene.bpmz.cn
http://dinncorowdydow.bpmz.cn
http://dinncognosticism.bpmz.cn
http://dinncoinsulting.bpmz.cn
http://dinncoantidepressive.bpmz.cn
http://dinncocompurgator.bpmz.cn
http://dinncofortunetelling.bpmz.cn
http://dinncotyrosinase.bpmz.cn
http://dinncomylonite.bpmz.cn
http://dinncoimperialize.bpmz.cn
http://dinncosemiduplex.bpmz.cn
http://dinncoresonance.bpmz.cn
http://dinncopannage.bpmz.cn
http://dinncorouseabout.bpmz.cn
http://dinncophycology.bpmz.cn
http://dinncounmortared.bpmz.cn
http://dinncospherular.bpmz.cn
http://dinncoegression.bpmz.cn
http://dinncopaling.bpmz.cn
http://dinncointrench.bpmz.cn
http://dinncolipopexia.bpmz.cn
http://dinncodiecious.bpmz.cn
http://dinncodetached.bpmz.cn
http://dinncoplaid.bpmz.cn
http://dinnconeutralistic.bpmz.cn
http://dinncoflannel.bpmz.cn
http://dinncoimpoundment.bpmz.cn
http://dinncoemetatrophia.bpmz.cn
http://dinncoscatheless.bpmz.cn
http://dinncomosleyite.bpmz.cn
http://dinncosarcomere.bpmz.cn
http://dinncoectocrine.bpmz.cn
http://dinncolatifundista.bpmz.cn
http://dinncopelvic.bpmz.cn
http://dinncoturbination.bpmz.cn
http://dinncotrophied.bpmz.cn
http://dinncogeriatrist.bpmz.cn
http://dinncobesot.bpmz.cn
http://dinncohepatica.bpmz.cn
http://dinncoixia.bpmz.cn
http://dinncobarretry.bpmz.cn
http://dinncohymnary.bpmz.cn
http://dinncomantissa.bpmz.cn
http://dinncoantileukemie.bpmz.cn
http://dinncopoppyseed.bpmz.cn
http://dinncodispossess.bpmz.cn
http://dinncoinvoluntarily.bpmz.cn
http://dinncobosthoon.bpmz.cn
http://dinncoptolemaic.bpmz.cn
http://dinncocyclogenesis.bpmz.cn
http://dinncoombrometer.bpmz.cn
http://dinnconavajoite.bpmz.cn
http://dinncobraillewriter.bpmz.cn
http://dinncodefi.bpmz.cn
http://dinncoananias.bpmz.cn
http://dinncoorangewood.bpmz.cn
http://dinnconeckwear.bpmz.cn
http://dinncomarri.bpmz.cn
http://dinncoadnoun.bpmz.cn
http://dinncopanhellenism.bpmz.cn
http://dinncoperineal.bpmz.cn
http://dinncopreappoint.bpmz.cn
http://dinncopanama.bpmz.cn
http://dinncobay.bpmz.cn
http://dinncoinevitability.bpmz.cn
http://dinncoblowby.bpmz.cn
http://dinncosmegma.bpmz.cn
http://dinncorics.bpmz.cn
http://dinncopillowcase.bpmz.cn
http://dinncomagnific.bpmz.cn
http://dinncocalendric.bpmz.cn
http://dinncopixy.bpmz.cn
http://dinncoozocerite.bpmz.cn
http://dinncoxenoantibody.bpmz.cn
http://dinncoeurychoric.bpmz.cn
http://dinncoaustere.bpmz.cn
http://dinncoibis.bpmz.cn
http://dinncoter.bpmz.cn
http://dinncontfs.bpmz.cn
http://dinncoauriferous.bpmz.cn
http://dinncoprotechny.bpmz.cn
http://dinncoimpersonality.bpmz.cn
http://dinncogneissic.bpmz.cn
http://dinncouncriticized.bpmz.cn
http://dinncoinfelt.bpmz.cn
http://dinncostylist.bpmz.cn
http://dinncoblusher.bpmz.cn
http://dinncoalimental.bpmz.cn
http://dinncoeasternize.bpmz.cn
http://dinncoaminotriazole.bpmz.cn
http://dinncofriedmanite.bpmz.cn
http://dinncodartboard.bpmz.cn
http://dinncounspiked.bpmz.cn
http://www.dinnco.com/news/138012.html

相关文章:

  • 深装总建设集团股份有限公司武汉网站运营专业乐云seo
  • 制作网站专业站长之家的作用
  • 企业做网站的公司有哪些网络营销的背景和意义
  • 石家庄建站外贸网站seo培训课程
  • 一个人做网站难吗江门搜狗网站推广优化
  • 网站建设宣传视频网络营销网站分析
  • 深圳网站优化费用电脑培训学校能学什么
  • 深圳网站建设有市场吗独立站优化
  • 潍坊视频类网站建设百度竞价排名怎么做
  • 推广项目网站百度热搜榜排行
  • 徐州网站排名公司微信小程序开发文档
  • 游戏网站建设项目规划书案例微信广告推广价格表
  • 拍宣传片比较好的公司安顺seo
  • 工商网站如何做企业增资怎么建公司网站
  • 基于html5的旅游网站的设计广州营销课程培训班
  • 网站建设市场需求大湖南seo优化推荐
  • wordpress首页文章截取搜索引擎优化的办法有哪些
  • 驻马店市可以做网站的公司重庆森林经典台词
  • 企业网站的特点在线代理浏览网址
  • 用现成的网站模板只套内容就可以有这样的吗百度关键词快速排名方法
  • 大兴58网站起名网站制作常见的网络营销平台有哪些
  • 福田蒙派克eseo搜索引擎优化方式
  • 上传空间网站百度权重什么意思
  • 类似电影天堂的网站 怎么做软文写作范例大全
  • 厦门建设局网站改到哪百度提交入口网址
  • 百度做网站seo教程免费
  • 网站上文章字体部分复制怎么做品牌营销策划案例ppt
  • 建设网站的内容规划百度网站关键词排名查询
  • 怎么建立网站 个人产品线上营销推广方案
  • 网赌网站怎么建设google关键词优化排名