弹性搜索不显示字段

Elastic search is not showing the fields

我是 Elastic 搜索的新手。我正尝试在 Python 中为我的一个大学项目实施它。我想使用弹性搜索作为简历索引器。一切正常,除了它显示 _source field 中的所有字段。我不想要一些字段,我尝试了太多但没有任何效果。下面是我的代码

es = Elastcisearch()
  query = {
"_source":{
    "exclude":["resume_content"]
            },
        "query":{
            "match":{
                "resume_content":{
                    "query":keyword,
                    "fuzziness":"Auto",
                    "operator":"and",
                    "store":"false"
                        }
                    }
                }
            }

    res = es.search(size=es_conf["MAX_SEARCH_RESULTS_LIMIT"],index=es_conf["ELASTIC_INDEX_NAME"], body=query)

return res

其中 es_conf 是我的本地字典。

除了上面的代码我还尝试了 _source:false ,_source:[name of my fields], fields:[name of my fields] 。我也在我的搜索方法中尝试了 store=False 。有任何想法吗?

你试过只使用 fields 吗?

这是一个简单的例子。我设置了一个包含三个字段的映射,(想象地)命名为 "field1""field2""field3":

PUT /test_index
{
   "mappings": {
      "doc": {
         "properties": {
            "field1": {
               "type": "string"
            },
            "field2": {
               "type": "string"
            },
            "field3": {
               "type": "string"
            }
         }
      }
   }
}

然后我索引了三个文档:

POST /test_index/doc/_bulk
{"index":{"_id":1}}
{"field1":"text11","field2":"text12","field3":"text13"}
{"index":{"_id":2}}
{"field1":"text21","field2":"text22","field3":"text23"}
{"index":{"_id":3}}
{"field1":"text31","field2":"text32","field3":"text33"}

假设我想在字段 "field2" 中查找包含 "text22" 的文档,但我只想 return "field1" 和“field2”。这是查询:

POST /test_index/doc/_search
{
    "fields": [
       "field1", "field2"
    ], 
    "query": {
        "match": {
           "field2": "text22"
        }
    }
}

其中 return 个:

{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 1,
      "successful": 1,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1.4054651,
      "hits": [
         {
            "_index": "test_index",
            "_type": "doc",
            "_id": "2",
            "_score": 1.4054651,
            "fields": {
               "field1": [
                  "text21"
               ],
               "field2": [
                  "text22"
               ]
            }
         }
      ]
   }
}

这是我使用的代码:http://sense.qbox.io/gist/69dabcf9f6e14fb1961ec9f761645c92aa8e528b

使用 Python 适配器进行设置应该很简单。