25

我正在运行一个简单的查询,如下所示:

{
  "query": {
    "term": {
      "statuses": "active"
    }
  },
  "script_fields": {
    "test": {
      "script": "_source.name"
    }
  }
}

问题是,一旦我引入script_fields,我就不再得到_source我的结果。

我试过了:

{
  "fields": [
    "_all"
  ],
  "query": {
    "term": {
      "statuses": "active"
    }
  },
  "script_fields": {
    "email": {
      "script": "_source.name"
    }
  }
}

{
  "fields": [
    "*"
  ],
  "query": {
    "term": {
      "statuses": "active"
    }
  },
  "script_fields": {
    "email": {
      "script": "_source.name"
    }
  }
}

但他们没有任何区别。除了 有没有办法_source退换货script_fields

4

2 回答 2

31

fields数组中,使其加载_source

{
  "stored_fields": [
    "_source"
  ],
  "query": {
    "term": {
      "statuses": "active"
    }
  },
  "script_fields": {
    "email": {
      "script": "_source.name"
    }
  }
}
于 2012-08-08T00:54:03.887 回答
1

这对我有用:

curl -X DELETE localhost:9200/a

curl -X POST localhost:9200/a/b/c -d '{"title" : "foo"}'

curl -X POST localhost:9200/a/_refresh

echo;

curl localhost:9200/a/_search?pretty -d '{
  "fields": [
    "_source"
  ],
  "query": {
    "match_all": {}
  },
  "script_fields": {
    "title_script": {
      "script": "_source.title"
    }
  }
}'

输出:

"hits" : {
  # ...
  "hits" : [ {
    # ...
    "_source" : {"title" : "foo"},
    "fields" : {
      "title_script" : "foo"
    }
  } ]
}
于 2014-01-27T09:16:40.683 回答