我正在为ElasticSearch进行工作,目的是将数据存储和获取为json。问题是当我使用搜索/突出显示功能时,ES将json视作文本/字符串,并且没有满足我的要求,即在搜索结果中获取存储的json的所有父项。
例如,如果我有一个像这样的json:{"jsonfile.htm":{"Headingtag":"100129","Sectiontext":{"part i":{"Headingtag":"p1","Sectiontext":{"Random Heading I":{"Sectiontext":"Impossible considered invitation him men instrument saw celebrated unpleasant."},"Random Heading II":{"Sectiontext":"Prevailed discovery immediate objection of ye at."}}}}}}当我们使用搜索或突出显示功能来“庆祝”文本时,它给我的结果是这样的:
[突出显示] =>数组
(
[细节] =>数组
(
[0] =>“:{”随机标题I“:{” Sectiontext“:”不可能考虑邀请他参加乐器庆祝的人
)
)
它将json作为字符串,并忽略父子关系。
谁能帮助我找出如何从结果中获取所有搜索到的文本 parent ?

最佳答案

您可能应该只在“突出显示”中使用使用*的功能。
如果我以你为例:

GET my-index/_search
{
  "query": {
    "multi_match": {
      "query": "celebrated",
      "fields": ["jsonfile.*"]
    }
  },
  "highlight": {
    "fields": {
      "jsonfile.*": {}
    }
  }
}
结果将是:
{
        "_index" : "test-5",
        "_type" : "_doc",
        "_id" : "r4fdAXQBw1rncBcgXr08",
        "_score" : 0.2876821,
        "_source" : {
          "jsonfile.htm" : {
            "Headingtag" : "100129",
            "Sectiontext" : {
              "part i" : {
                "Headingtag" : "p1",
                "Sectiontext" : {
                  "Random Heading I" : {
                    "Sectiontext" : "Impossible considered invitation him men instrument saw celebrated unpleasant."
                  },
                  "Random Heading II" : {
                    "Sectiontext" : "Prevailed discovery immediate objection of ye at."
                  }
                }
              }
            }
          }
        },
        "highlight" : {
          "jsonfile.htm.Sectiontext.part i.Sectiontext.Random Heading I.Sectiontext" : [
            "Impossible considered invitation him men instrument saw <em>celebrated</em> unpleasant."
          ]
        }
      }
当然,如果您不使用is,也可以在查询中禁用_source。

关于json - 如何使用Elasticsearch作为Json存储和获取文档,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63450440/

10-15 22:17