如何找到在弹性搜索中找到的结果来自哪个子类型


how to find from which sub-type was the result found in 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'
        }]
    }
}

我的查询是,当我搜索great person时,它也应该返回它的sub-type,比如name or type or description or address

例如:

http://localhost:9200/some-index/type?q=great person

因此,除了完整的结果外,它还应该返回其子类型,即:description。我试过highlighter,但没有用。

请帮忙。

这个怎么样?

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=great person world),它会给你:

 "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>"
           ]
        }
     }
  ]