1.most_fields 这种方式搜索也存在某些问题

  • 它不能使用 operator 或 minimum_should_match 参数来降低次相关结果造成的长尾效应。

2.词 peter 和 smith 都必须出现,但是可以出现在任意字段中。

3.cross_fields 类型首先分析查询字符串并生成一个词列表,然后它从所有字段中依次搜索每个词。这种不同的搜索方式很自然的解决了 字段中心式 查询三个问题中的二个

4.经典案例

GET /_validate/query?explain
{
"query": {
"multi_match": {
"query": "peter smith",
"type": "cross_fields",
"operator": "and",
"fields": [ "first_name", "last_name" ]
}
}
}

参考:https://www.elastic.co/guide/cn/elasticsearch/guide/current/_cross_fields_queries.html

---------------------------------------------------------------------------------------------------------------------------

1.正则结合cross_fields

PUT /addressbook/_doc/
{
"name":"test url",
"mobile":"123/456/url"
}
GET /addressbook/_search
{
"query": {
"multi_match": {
"query": ".*456.*", #.*去掉也一样的效果
"fields": ["name","mobile"]
}
}
}

---------------------------------------------------------------------------------------------------------

3.中文搜索,cross_field

3.1.定义映射

PUT yanbao072702
"mappings": {
"_doc"{
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"author": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"institution": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"industry": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"grade": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"doc_type": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"time": {
"type": "date" ,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"doc_uri": {
"type": "text",
"index":false
},
"doc_size": {
"type": "integer",
"index":false
},
"market": {
"type": "byte"
}
}
}
}
}'

3.2 插入数据

PUT /yanbao0727/_bulk
{"index":{"_id":""}}
{"title":"香港-报告","author":"中信证券","institution":"中信中国","industry":"testindustry","grade":"testgrade","doc_type":"testdoc_type","time":"2019-07-27","doc_uri":"www.baidu.com","doc_size":"10M","market":"cn"}

3.3 测试分词器

POST _analyze
{
"analyzer": "ik_smart",
"text":"test报告"
}

3.4 搜索“君安 报告”

POST /yanbao0727/_search
{
"query": {
"multi_match": {
"query": "报告 君安",
"type": "cross_fields",
"fields": ["author","title"]
}
}
}

3.5 搜索结果

{
"_index" : "yanbao0727",
"_type" : "_doc",
"_id" : "",
"_score" : 2.6205368,
"_source" : {
"title" : "test报告",
"author" : "国泰君安",
"institution" : "君安证券",
"industry" : "testindustry",
"grade" : "testgrade",
"doc_type" : "testdoc_type",
"time" : "2019-07-27",
"doc_uri" : "www.baidu.com",
"doc_size" : "10M",
"market" : "cn"
}
}

参考:https://www.cnblogs.com/dxf813/p/8447196.html

elasticsearch的cross_fields查询的更多相关文章

  1. elasticsearch GIS空间查询问题解决

    在GIS行业的应用越来越广泛,GIS最常用根据区域进行空间数据查询     我定义了两个方法,一起来看一下: /** * geodistance filter * 一个过滤器来过滤基于一个特定的距离从 ...

  2. Elasticsearch文档查询

    简单数据集 到目前为止,已经了解了基本知识,现在我们尝试用更逼真的数据集,这儿已经准备好了一份虚构的JSON,关于客户银行账户信息的.每个文档的结构如下: { , , "firstname& ...

  3. Elasticsearch(GEO)空间检索查询

    Elasticsearch(GEO)空间检索查询python版本 1.Elasticsearch ES的强大就不用多说了,当你安装上插件,搭建好集群,你就拥有了一个搜索系统. 当然,ES的集群优化和查 ...

  4. 利用kibana插件对Elasticsearch进行bool查询

    #bool查询#老版本的filtered查询已经被bool代替#用 bool包括 must should must_not filter来完成 ,格式如下:#bool:{#  "filter ...

  5. java操作elasticsearch实现前缀查询、wildcard、fuzzy模糊查询、ids查询

    1.前缀查询(prefix) //prefix前缀查询 @Test public void test15() throws UnknownHostException { //1.指定es集群 clus ...

  6. java操作elasticsearch实现条件查询(match、multiMatch、term、terms、reange)

    1.条件match query查询 //条件查询match query @Test public void test10() throws UnknownHostException { //1.指定e ...

  7. java使用elasticsearch进行模糊查询-已在项目中实际应用

    java使用elasticsearch进行模糊查询 使用环境上篇文章本人已书写过,需要maven坐标,ES连接工具类的请看上一篇文章,以下是内容是笔者在真实项目中运用总结而产生,并写的是主要方法和思路 ...

  8. Elasticsearch 常用基本查询

    安装启动很简单,参考官网步骤:https://www.elastic.co/downloads/elasticsearch 为了介绍Elasticsearch中的不同查询类型,我们将对带有下列字段的文 ...

  9. kibana和ElasticSearch的信息查询检索

    使用kibana来进行ElasticSearch的信息查询检索 大家经常会听到使用ELK搭建日志管理平台.完成日志聚合检索的功能,那么这个平台到底是个什么概念,怎么搭建,怎么使用呢? ELK包括Ela ...

随机推荐

  1. 使用fiddler抓取jmeter发送的请求

    使用jmeter发送请求时,有时需要查看发送的请求是否合理,可以使用fiddler更直观的抓取并查看jmeter发送的请求.步骤如下:1.设置fidder-connections 端口号为8888 2 ...

  2. uniapp在在页面跳转时,若URL太长的字符串会导致数据传递失败

    url有长度限制,太长的字符串会传递失败,可使用窗体通信.全局变量,或encodeURIComponent等多种方式解决,如下为encodeURIComponent示例的解决方法. <navig ...

  3. EF 批量添加数据

    原文:https://www.cnblogs.com/liuruitao/p/10049191.html 原文:https://www.cnblogs.com/yaopengfei/p/7751545 ...

  4. 提示 ToolTip

    <StackPanel> <Button Content="按钮1" ToolTip="这是个按钮1" HorizontalAlignment ...

  5. java输出txt文件到桌面

    private static void outputTxt(String ExportFailStudentMsg){ FileSystemView fsv = FileSystemView.getF ...

  6. bootstrap面板的使用

    <div class="panel panel-primary"> <div class="panel-heading"> 头部 < ...

  7. P1200 [USACO1.1]你的飞碟在这儿Your Ride Is Here

    输入格式: 第1行:一个长度为111到666的大写字母串,表示彗星的名字. 第2行:一个长度为111到666的大写字母串,表示队伍的名字. 输出格式: 如果能搭配,就输出“GO”,否则输出“STAY” ...

  8. HBuilder开发MUI web app溢出页面上下无法滚动问题

    因为没有对页面初始化,所以页面溢出部分不会显示,要解决此问题需要加上下面代码: JS代码: (function($){$(".mui-scroll-wrapper").scroll ...

  9. github搜索不到代码的问题

    Hi team, Please check the following three query url :https://github.com/Konctantin/GreyMagic/search? ...

  10. drawable SVG 使用

    Android会使用一些规则来去帮我们匹配最适合的图片.什么叫最适合的图片?比如我的手机屏幕密度是xxhdpi,那么drawable-xxhdpi文件夹下的图片就是最适合的图片.因此,当我引用andr ...