第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Elasticsearch 中索引對象列表?

如何在 Elasticsearch 中索引對象列表?

慕哥6287543 2022-05-19 18:36:14
我攝取到 ElasticSearch 中的文檔格式如下所示:{   'id':'514d4e9f-09e7-4f13-b6c9-a0aa9b4f37a0'   'created':'2019-09-06 06:09:33.044433',   'meta':{      'userTags':[         {            'intensity':'1',            'sentiment':'0.84',            'keyword':'train'         },         {            'intensity':'1',            'sentiment':'-0.76',            'keyword':'amtrak'         }      ]   }}...用 python 攝取:r = requests.put(itemUrl, auth = authObj, json = document, headers = headers)這里的想法是 ElasticSearch 將keyword,intensity和sentiment視為以后可以查詢的字段。但是,在 ElasticSearch 方面,我可以觀察到這并沒有發(fā)生(我使用 Kibana 搜索 UI)——相反,我看到字段“meta.userTags”的值是整個對象列表。如何在列表中創(chuàng)建 ElasticSearch 索引元素?
查看完整描述

2 回答

?
德瑪西亞99

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個贊

您不需要特殊的映射來索引列表 - 每個字段都可以包含一個或多個相同類型的值。請參閱數(shù)組數(shù)據(jù)類型。

在對象列表的情況下,它們可以被索引為objectnested數(shù)據(jù)類型。默認(rèn)彈性使用object數(shù)據(jù)類型。在這種情況下,您可以查詢meta.userTags.keywordor/and meta.userTags.sentiment。結(jié)果將始終包含具有獨(dú)立匹配值的整個文檔,即。搜索keyword=train,sentiment=-0.76您將找到帶有id=514d4e9f-09e7-4f13-b6c9-a0aa9b4f37a0.

如果這不是您想要的,您需要為 field 定義嵌套數(shù)據(jù)類型映射userTags并使用嵌套查詢。


查看完整回答
反對 回復(fù) 2022-05-19
?
嗶嗶one

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個贊

我使用您提供的文檔正文創(chuàng)建了一個新索引“testind”并使用 Postman REST 客戶端鍵入“testTyp”。:


POST http://localhost:9200/testind/testTyp

{

   "id":"514d4e9f-09e7-4f13-b6c9-a0aa9b4f37a0",

   "created":"2019-09-06 06:09:33.044433",

   "meta":{

      "userTags":[

         {

            "intensity":"1",

            "sentiment":"0.84",

            "keyword":"train"

         },

         {

            "intensity":"1",

            "sentiment":"-0.76",

            "keyword":"amtrak"

         }

      ]

   }

}

當(dāng)我查詢索引的映射時,這就是我得到的:


GET http://localhost:9200/testind/testTyp/_mapping

{  

  "testind":{  

    "mappings":{  

      "testTyp":{  

        "properties":{  

          "created":{  

            "type":"text",

            "fields":{  

             "keyword":{  

                "type":"keyword",

                "ignore_above":256

              }

            }

          },

          "id":{  

            "type":"text",

            "fields":{  

              "keyword":{  

                "type":"keyword",

                "ignore_above":256

              }

            }

          },

          "meta":{  

            "properties":{  

              "userTags":{  

                "properties":{  

                  "intensity":{  

                    "type":"text",

                    "fields":{  

                      "keyword":{  

                        "type":"keyword",

                        "ignore_above":256

                      }

                    }

                  },

                  "keyword":{  

                    "type":"text",

                    "fields":{  

                      "keyword":{  

                        "type":"keyword",

                        "ignore_above":256

                      }

                    }

                  },

                  "sentiment":{  

                    "type":"text",

                    "fields":{  

                      "keyword":{  

                        "type":"keyword",

                        "ignore_above":256

                      }

                    }

                  }

                }

              }

            }

          }

        }

      }

    }

  }

}

正如您在映射中看到的那樣,字段是映射的一部分,將來可以根據(jù)需要進(jìn)行查詢,所以只要字段名稱不是其中之一,我就不會在這里看到問題 - https://www .elastic.co/guide/en/elasticsearch/reference/6.4/sql-syntax-reserved.html(您可能希望避免使用“關(guān)鍵字”一詞,因?yàn)樯院笤诰帉懰阉鞑樵儠r可能會造成混淆,因?yàn)樽侄蚊皖愋投际窍嗤?- '關(guān)鍵字')。另外,請注意一件事,映射是通過動態(tài)映射創(chuàng)建的(https://www.elastic.co/guide/en/elasticsearch/reference/6.3/dynamic-field-mapping.html#dynamic-field-mapping) 在 Elasticsearch 中,因此數(shù)據(jù)類型由 elasticsearch 根據(jù)您提供的值確定。但是,這可能并不總是準(zhǔn)確的,因此為了防止您可以使用 PUT _mapping API 為索引定義自己的映射,并且然后防止將類型中的新字段添加到映射中。


查看完整回答
反對 回復(fù) 2022-05-19
  • 2 回答
  • 0 關(guān)注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號