当输入JSON具有“ _source”字段时,ES没有结果

时间:2019-07-29 12:52:27

标签: json elasticsearch postman

当输入JSON具有“ _source”字段时,则输出JSON没有用于搜索的输出。

有两种情况。 情况_1:输入JSON确实具有“ _source”字段,并且输出为Null 情况_2:输入JSON没有“ _source”字段,而输出已在ES中搜索了整个字段的值

case_1具有“ _ source”:[“ coreid”,“ program_id”],

{
    "_source": [" coreid ", " program_id " ],
       "query": {
        "bool": {
            "should": [
                {
                    "bool": 
                    {
                        "must": [
                            {"match": {"tu_tm": { "query": "tu"   }  } },
                            {"match": {"program_id": {"query": "86328" }  } }
                                ]
                    }
                },
                {
                    "bool": 
                    {
                        "must": [
                            {"match": {"tu_tm": {"query": "tu"  }  }  },
                            {"match": {"program_id": {"query": "86330" } } }
                                ]
                    }
                },
                {
                    "bool": {
                        "must": [
                            {
                                "match": {
                                    "tu_tm": {
                                        "query": "tu"
                                    }
                                }
                            },

                    }
                }
            ]
        }
    }
}

输出具有“ _ source”:{}

{
  "took": 7,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 3,
    "max_score": 1.000008,
    "hits": [
      {
        "_index": "matching_tool",
        "_type": "data",
        "_id": "THcc2msB1g08C8plFbE0",
        "_score": 1.000008,
        "_source": {}
      }

1 个答案:

答案 0 :(得分:1)

更改您的_source定义

"_source": [" coreid ", " program_id " ],

"_source": ["coreid", "program_id" ],

不需要在字段ID周围加上空格。

希望有帮助。