栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用match_phrase组合过滤器-Elastic 1.7

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用match_phrase组合过滤器-Elastic 1.7

最终,我能够重现该问题,

"include_in_parent":true,
因为您遇到了我在评论中提到的错误,因此看起来好像在映射中错过了。。

为了解决此问题,我使用了相同的映射为您提供,但

"include_in_parent":true,
address
嵌套字段的顶级添加了该问题。为简便起见,仅提供
address
部分修改的映射。

"addresses": { "type": "nested", "include_in_parent": true, --> added only this in your mapping. "properties": {   "address": {     "type": "string"   },   "city": {     "type": "string",     "index": "not_analyzed"   },   "city_id": {     "type": "long"   },   "country": {     "type": "string",     "index": "not_analyzed"   },   "county": {     "type": "string",     "index": "not_analyzed"   },   "county_id": {     "type": "long"   },   "id": {     "type": "long"   },   "location": {     "type": "geo_point"   },   "parameterized": {     "type": "string"   },   "state": {     "type": "string",     "index": "not_analyzed"   },   "state_id": {     "type": "long"   },   "zip": {     "type": "string",     "index": "not_analyzed"   } }          }

之后收录一些样本文档,其中有不同的价值观

address
name
PARAM,以验证我的搜索查询的一个正确的结果。

最后的搜索查询包括两个过滤器,请注意,我删除 了父文档中包含的地址字段中嵌套部分,因此您现在就可以直接对其进行查询。
该查询看起来非常简单,现在可以提供预期的结果。

{  "query": {    "match_phrase": {      "name": "aaron"    }  },  "filter": {    "bool": {      "must": [{        "query": {          "match_phrase": { "address": "scarborough"          }        }      },      {       "query": {          "match_phrase": { "phone": "813-689-6889"          }        }      }]    }  }}

示例文档上的输出

 "hits": [ {     "_index": "so-match-phrase",     "_type": "pl_people",     "_id": "4",     "_score": 0.19178301,     "_source": {         "resource": "Person",         "parameterized": "813106-aaron-mcguire",         "created_at": "2011-10-29T19:51:24.000-05:00",         "updated_at": "2014-12-11T07:21:08.000-06:00",         "name": "aaron McGuire",         "title": null,         "photo": {  "url": "/assets/140x140.gif"         },         "description": null,         "short_description": null,         "time": "2014-12-11",         "show_path": "/people/813106-aaron-mcguire",         "published": true,         "aliases": [],         "phone": "813-689-6889",         "date_of_birth": "1991-03-01",         "first_name": "Aaron",         "middle_name": "",         "last_name": "McGuire",         "delimiters": [],         "market": null,         "region": null,         "most_recent_organization": null,         "households": [],         "court_cases": [],         "addresses": [  {      "id": 1,      "parameterized": "1",      "address": "Scarborough road",      "zip": "L5A2A9",      "city": "Ontario",      "country": "USA",      "state": "California",      "location": null,      "state_id": null,      "county_id": null,      "city_id": null  }         ],         "id": "813106"     } }, {     "_index": "so-match-phrase",     "_type": "pl_people",     "_id": "1",     "_score": 0.19178301,     "_source": {         "resource": "Person",         "parameterized": "813106-aaron-mcguire",         "created_at": "2011-10-29T19:51:24.000-05:00",         "updated_at": "2014-12-11T07:21:08.000-06:00",         "name": "Aaron McGuire",         "title": null,         "photo": {  "url": "/assets/140x140.gif"         },         "description": null,         "short_description": null,         "time": "2014-12-11",         "show_path": "/people/813106-aaron-mcguire",         "published": true,         "aliases": [],         "phone": "813-689-6889",         "date_of_birth": "1991-03-01",         "first_name": "Aaron",         "middle_name": "",         "last_name": "McGuire",         "delimiters": [],         "market": null,         "region": null,         "most_recent_organization": null,         "households": [],         "court_cases": [],         "addresses": [  {      "id": 1,      "parameterized": "1",      "address": "123 Scarborough road",      "zip": "L5A2A9",      "city": "Ontario",      "country": "USA",      "state": "California",      "location": null,      "state_id": null,      "county_id": null,      "city_id": null  }         ],         "id": "813106"     } }        ]


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/426710.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号