3

我正在向其发布查询,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": {}
            }
        ]
    }
}
4

3 回答 3

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

于 2015-11-17T13:39:48.713 回答
0

解决方案:

在 elasticsearch 配置文件夹中,打开 elasticsearch.yml 并将 cluster.name 设置为不同的值,然后重新启动 elasticsearch.bat

于 2013-08-14T16:47:12.513 回答
0

我曾经不小心在源数组中传递了一个字段,但它也不存在。例如"_source": ["bazinga"],在聚合结果source中是空的。

所以也许你可以简单地将一个完全不相关的字符串传递到_source数组中。这可能是一个更好的解决方案,而不是在elasticsearch.yml文件中进行更改。

于 2018-05-11T12:27:32.650 回答