使用ElasticSearch对父/子文档进行复杂查询

时间:2012-03-09 16:06:12

标签: elasticsearch

考虑这个记录结构

"place": {
  "id": "4f58e38866eaa71e74000027",
  "name": "Some name",
  "point" [14.53535, 56.32535],
  "hostname": "Something",
  "locality": "something",
  "type": "Some type",
  "average_price": 67
}

"container": {
  "title": "Something",
  "category": "Something"
}

"row": {
  "name": "Something",
  "description": "Something",
  "price": 45,
  "markings_array": ['some_tag', 'some_tag'],
  "prioritized": true
}

我正在努力实现这个目标:

  • 按place.name
  • 上的字母顺序排序
  • 按地点距离排序
  • 按ID列
  • 排序/提升地点
  • 提升最接近给定参数点的地方
  • 如果他们被禁止的话会增加行数
  • 在place.name
  • 上随机排序
  • 按place.average_price
  • 排序
  • 对place.hostname和place.locality
  • 的术语查询
  • row.name
  • 上的字符串查询
  • facet on container.title
  • facet on row.markings_array

结果最终应该以这种格式使用,'中心对象'是容器: 编辑:'中心对象'也可以是这个地方。

[{
  "_score" : 183.96391,
  "container": {
    "title": "something",
    "category": "something",
    "place": {
      "id": "4f58e38866eaa71e74000027"
      "name": "Some name",
      "point" [14.53535, 56.32535],
      "hostname": "Something",
      "locality": "something",
      "type": "Some type" 
    },
    "rows": [
      {
        "_score": 183.96391,
        "name": "Something",
        "description": "Something"
        "price": 45,
        "markings_array" ['some_tag', 'some_tag']
      },
      {
        "_score": 133.96391,
        "name": "Something",
        "description": "Something"
        "price": 45,
        "markings_array" ['some_tag', 'some_tag']
      },
      {
        "_score": 123.96391,
        "name": "Something",
        "description": "Something"
        "price": 45,
        "markings_array" ['some_tag', 'some_tag']
      }
    ]
  }
}]

行应按其分数排序。 如何执行此查询?

我现在所做的是索引每一行的所有字段,然后针对包含行的索引执行搜索。

要获得所需的输出,我必须循环通过结果并将它们按父级等分组。问题是我还需要在地方或容器上进行评分,因为我将在列表中显示带有位置和行的容器。 / p>

有更好的方法吗?

由于

0 个答案:

没有答案