如何将ES中的所有数据设置为未分析?

2024-03-29 15:19:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个SQS队列中存储了大量json格式的json数据。我有一个python脚本,它基本上从SQS中提取数据,然后将其索引到ES。代码片段如下所示:

doc = {
      "settings" : {
      "number_of_shards" : 1
       },
    "mappings" : {
             "_default_":{
                      "_timestamp" : {
                      "enabled" : 'true',
                      "store" : 'true'
                            }
                        }
              }
            }
es = Elasticsearch()
h = { "Content-type":"application/json" }
res = requests.request("POST","http://localhost:9200/"+index_name+"/",headers=h,data=json.dumps(doc))
post = es.index(index=index_name , doc_type='server' , id =1 , body=json.dumps(new_list))

所以基本上我的搜索不是很有效,我读到了https://www.elastic.co/guide/en/elasticsearch/guide/current/aggregations-and-analysis.html,我基本上想确保ES不会把我的数据对象分成更小的块。我该怎么做才能解决这个问题?在


Tags: 数据name脚本jsontrueindexdoces
1条回答
网友
1楼 · 发布于 2024-03-29 15:19:11

如果希望索引中的每个string字段都成为not analyzed字符串,则需要使用Dynamic templates。在

 PUT index_name
 {
 "mappings": {
  "type_name": {
     "dynamic_templates": [
        {
           "strings": {
               "match_mapping_type": "string",
              "mapping": {
                 "type": "string",
                 "index": "not_analyzed"
              }
           }
        }
       ]
    }
   }
 }

相关问题 更多 >