php – 如何找到在elasticsearch中找到的结果的子类型?

大家好,提前谢谢,

我以下列方式在elasticsearch服务器上索引数据

{
    'main_index':{
        'type':[{
            'name':'john deo',
            'type':'accountant',
            'description':'john deo is a great person',
            'address':'somewhere in the world'
        },
        {
            'name':'calvin kalvin',
            'type':'designer',
            'description':'calvin kalvin is john deo's best friend',
            'address':'somewhere near'
        }]
    }
}

我的查询是,当我搜索伟大的人时,它也应该返回它的子类型,例如名称或类型或描述或地址

例如.:

http:// localhost:9200 / some-index / type?q =好人

因此,除了完整的结果,它还应返回其子类型ie :: description.我试过荧光笔,但没用.

请帮忙.

最佳答案 这个怎么样?

GET /my_index/type/_search?q=great person
{
  "highlight": {
    "fields": {"name": {},"type": {},"description": {},"address": {}}
  }
}

哪个给你:

 "hits": [
     {
        "_index": "my_index",
        "_type": "type",
        "_id": "1",
        "_score": 0.10848885,
        "_source": {
           "name": "john deo",
           "type": "accountant",
           "description": "john deo is a great person",
           "address": "somewhere in the world"
        },
        "highlight": {
           "description": [
              "john deo is a <em>great</em> <em>person</em>"
           ]
        }
     }
  ]

如果你把“世界”放在搜索查询中(所以q =伟人世界),它会给你:

 "hits": [
     {
        "_index": "my_index",
        "_type": "type",
        "_id": "1",
        "_score": 0.13287117,
        "_source": {
           "name": "john deo",
           "type": "accountant",
           "description": "john deo is a great person",
           "address": "somewhere in the world"
        },
        "highlight": {
           "address": [
              "somewhere in the <em>world</em>"
           ],
           "description": [
              "john deo is a <em>great</em> <em>person</em>"
           ]
        }
     }
  ]
点赞