gpt4 book ai didi

ElasticSearch _Source 在返回时始终为空

转载 作者:行者123 更新时间:2023-11-29 02:57:19 25 4
gpt4 key购买 nike

我正在向 http://localhost:9200/movie_db/movie/_search 发布查询,但 _source 属性在返回结果中始终为空。我启用了它,但这没有用。

电影数据库:

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": {}
}
]
}
}

最佳答案

我遇到了同样的问题:尽管在我的查询和映射中启用了 _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

关于ElasticSearch _Source 在返回时始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18233461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com