我向http://localhost:9200/movie_db/movie/_search
发布了一个查询,但_source属性在返回resposne上始终为空。我启用了它,但这没有帮助。
电影资料库:
TRY DELETE /movie_db
PUT /movie_db {"mappings": {"movie": {"properties": {"title": {"type": "string", "analyzer": "snowball"}, "actors": {"type": "string", "position_offset_gap" : 100, "analyzer": "standard"}, "genre": {"type": "string", "index": "not_analyzed"}, "release_year": {"type": "integer", "index": "not_analyzed"}, "description": {"_source": true, "type": "string", "analyzer": "snowball"}}}}}
BULK INDEX movie_db/movie
{"_id": 1, "title": "Hackers", "release_year": 1995, "genre": ["Action", "Crime", "Drama"], "actors": ["Johnny Lee Miller", "Angelina Jolie"], "description": "High-school age computer expert Zero Cool and his hacker friends take on an evil corporation's computer virus with their hacking skills."}
{"_id": 2, "title": "Johnny Mnemonic", "release": 1995, "genre": ["Science Fiction", "Action"], "actors": ["Keanu Reeves", "Dolph Lundgren"], "description": "A guy with a chip in his head shouts incomprehensibly about room service in this dystopian vision of our future."}
{"_id": 3, "title": "Swordfish", "release_year": 2001, "genre": ["Action", "Crime"], "actors": ["John Travolta", "Hugh Jackman", "Halle Berry"], "description": "A cast of characters challenge society's commonly held view that computer experts are not the beautiful people. Somehow, the CIA is hacked in under 5 minutes."}
{"_id": 4, "title": "Tomb Raider", "release_year": 2001, "genre": ["Adventure", "Action", "Fantasy"], "actors": ["Angelina Jolie", "Jon Voigt"], "description": "The story of a girl and her quest for antiquities in the face of adversity. This epic is adapter from its traditional video-game format to the big screen"}
查询:
{
"query" :
{
"term" : { "genre" : "Crime" }
},
}
结果:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.30685282,
"hits": [
{
"_index": "movie_db",
"_type": "movie",
"_id": "3",
"_score": 0.30685282,
"_source": {}
},
{
"_index": "movie_db",
"_type": "movie",
"_id": "1",
"_score": 0.30685282,
"_source": {}
}
]
}
}
答案 0 :(得分:1)
我遇到了同样的问题:尽管在我的查询和我的映射中启用了_source
,_source
仍然是{}
。
你提出的在elasticsearch.yml中设置cluster.name的解决方案给了我一个提示,即问题必须是旧集群中的一些隐藏设置。
我发现我有一个索引模板定义附带了我安装的插件(在我的情况下是elasticsearch-transport-couchbase),其中说
"_source" : {
"includes" : [ "meta.*" ]
},
从而隐含地排除了meta.*
以外的所有字段。
检查您的模板:
curl -XGET localhost:9200/_template/?pretty
我删除了couchbase
模板,如此
curl -XDELETE localhost:9200/_template/couchbase
并创建了一个新的,几乎完全相同的但启用了source
。
以下是: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html
答案 1 :(得分:0)
解决方案:
在elasticsearch配置文件夹中,打开elasticsearch.yml并将cluster.name设置为其他值,然后重新启动elasticsearch.bat
答案 2 :(得分:0)
我曾经不小心通过了源数组中的单个字段,而且它也不存在。仅举例来说"_source": ["bazinga"]
并且在汇总结果中source
为空。
所以也许你可以简单地将一个完全不相关的字符串传递给_source
数组。这可以是更好的解决方案,而不是在elasticsearch.yml
文件中进行更改。