Elasticsearch变更响应格式

时间:2019-10-01 10:58:33

标签: jquery json elasticsearch

我正在使用/cairn/_doc/id将多个文件数据保存到 Elasticsearch ,其中id是文件的唯一ID。示例数据如下。

var file = 1;
var meraData = '{"data":[{"page":"1","lineid":"00f6","text":"OIL AND NATURAL ","fileId":"175"},{"page":"1","lineid":"4411","text":"Source Rock Geochemistry","fileId":"175"},{"page":"1","lineid":"c267","text":"CHENNAI -600034","fileId":"175"}]}';
function sendElastic(meraData, file){
    $.ajax({
        type:'POST',
        url: 'https://search-cairn-o3fpbj34hxgttac6b3dnuc37ie.us-east-1.es.amazonaws.com/cairn/_doc/'+file,
        data:JSON.stringify(meraData),
        contentType: "application/json",
        dataType: "json",
        success:function(data){
            console.log(data);
        },
        error: function(data){
            console.log(data.responseJSON);
        }
    });
}

cairn/_search?q=OIL发出 GET 请求后 响应如下。

{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 0.57148063,
    "hits": [
      {
        "_index": "cairn",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.57148063,
        "_source": {
          "data": [
            {
              "page": "1",
              "lineid": "00f6",
              "text": "OIL AND NATURAL ",
              "fileId": "175"
            },
            {
              "page": "1",
              "lineid": "4411",
              "text": "Source Rock Geochemistry",
              "fileId": "175"
            },
            {
              "page": "1",
              "lineid": "c267",
              "text": "CHENNAI -600034",
              "fileId": "175"
            }
          ]
        }
      }
    ]
  }
}

如何更改响应格式以在_source.data数组中仅显示完全匹配的数组值? 例如,对于查询“ OIL”

{
  "page": "1",
  "lineid": "00f6",
  "text": "OIL AND NATURAL ",
  "fileId": "175"
}

应返回_source.data

还是可以像/cairn/_doc/id/lineid一样保存它?

0 个答案:

没有答案