簡體   English   中英

彈性搜索未顯示字段

[英]Elastic search is not showing the fields

我是彈性搜索的新手。 我正在嘗試為我的一個大學項目用Python實現它。 我想將Elastic搜索用作簡歷索引器。 除了顯示_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)

返回資源

es_conf是我的本地字典。

除了上面的代碼,我還嘗試了_source:false_source:[name of my fields]fields:[name of my fields] 我也嘗試在搜索方法中使用store=False 有任何想法嗎?

您是否嘗試僅使用字段

這是一個簡單的例子。 我設置了三個字段的映射,(想象中的)名為"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"文檔,但是我只想返回"field1"和“ field2 ”的內容。 這是查詢:

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

返回:

{
   "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適配器進行設置應該很簡單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM