简体   繁体   English

在弹性搜索中使用多个文档索引 JSON 文件

[英]Indexing a JSON file with multiple documents in elastic search

I am new to elasticsearch i want to index a JSON file and perform search queries from elasticsearch我是 elasticsearch 的新手,我想索引 JSON 文件并从 elasticsearch 执行搜索查询

How can I index this json and perform queries to get value if i pass parameter as "field3.innerfield": "someval"如果我将参数传递为“field3.innerfield”:“someval”,我如何索引这个 json 并执行查询以获取值

I have tried indexing this file with helpers.bulk and search but it returns all the fields instead of a selected field.我曾尝试使用helpers.bulk和搜索索引此文件,但它返回所有字段而不是选定字段。

Below is the JSON sample下面是 JSON 样品

[
    {
        "id": "someid",
        "metadata": {
            "docType": "value",
            "otherfield": " ",
            morefields
            .
            .
        },
        "field1":"value1",
        "field2":"value2,
        "field3": [
            {
                "innerfield": "someval",
                "innerfield1":[
                    "kind of a paragraph"
                ]
            }
        ],
        "field4": [
            {
                "innerfield": "someval",
                "innerfield1": "kind of a paragraph"
            }
        ],
    },
    { again the format repeats with different id but same fields
    },
    {
    }

]

Your question lacks clarity however what I understood is that you want to fetch values from its key for a nested json.您的问题不清楚,但我的理解是您想从嵌套 json 的键中获取值。 You can do that in the following way as shown below.您可以通过以下方式执行此操作,如下所示。 Parse it multiple times and make the required changes as per your need.多次解析它并根据您的需要进行所需的更改。

import json
data = data.apply(lambda x: json.loads(json.loads(x).get("metadata","{}")).get("doctype") if x else None)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM