您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用match_phrase组合过滤器-Elastic 1.7

使用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"
              }
            }
          }

之后收录一些样本文档,其中有不同的价值观addressnamePARAM,以验证我的搜索查询一个正确的结果。

最后的搜索查询包括两个过滤器,请注意,我删除 的 该查询看起来非常简单,现在可以提供预期的结果。

{
  "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"
                }
            }
        ]
其他 2022/1/1 18:13:57 有580人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶