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. 5 解析器、url路由控制、分页、渲染器和版本

    1 数据解析器 1 什么是解析器 相当于request 中content-type 对方传什么类型的数据,我接受什么样的数据:怎样解析 无论前面传的是什么数据,都可以解开 例如:django不能解析j ...

  2. 【Springboot】Springboot整合Ehcache

    刚刚项目上线了,记录下使用的技术...... EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider. Ehcache的特点 ( ...

  3. 解决微信小程序textarea 里输入的文字或者是placeholder里的值,飘到弹出view上

    在uniapp微信小程序开发中使用textarea,结果发现输入框的问题浮动起来,view无法把他覆盖,设法设置index的值也不生效,所以只能是通过条件v-if或者v-show使其隐藏就可以了

  4. What is Double 11 in China? Is it a famous festival?

    "1" means single, 11th, November is quadruple single!! What a tragedy for those single you ...

  5. java内存区域以及GC回收

    参考资料: http://www.cnblogs.com/zhguang/p/3257367.html 概要: Java GC机制主要完成3件事:确定哪些内存需要回收,确定什么时候需要执行GC,如何执 ...

  6. 线段树初步——转载自ljc20020730

    线段树初步   线段树模板1:https://www.luogu.org/problem/show?pid=3372 线段树模板2:https://www.luogu.org/problem/show ...

  7. 在vue中引入layer弹框的简易方法

    npm i --save layui-layer 2.在main.js中引入 import layer from "layui-layer"; 3.然后就可以在各个组件中使用lay ...

  8. codeforces555B

    Case of Fugitive CodeForces - 555B Andrewid the Android is a galaxy-famous detective. He is now chas ...

  9. Android蓝牙通信

    Android为蓝牙设备之间的通信封装好了一些调用接口,使得实现Android的蓝牙通信功能并不困难.可通过UUID使两个设备直接建立连接. 具体步骤: 1. 获取BluetoothAdapter实例 ...

  10. Python实现telnet命令测试防火墙

    Python实现telnet命令测试防火墙 telnet主要用于测试主机端口是否开通 ping主要是用来测试网络是否畅通和主机是否正在使用 使用Python实现Telnet测试主机端口是否开通的功能. ...