gpt4 book ai didi

python - ElasticSearch - python 别名类型

转载 作者:太空宇宙 更新时间:2023-11-03 18:11:17 24 4
gpt4 key购买 nike

我有一个带有zzz索引和设备文档类型的elasticsearch实例。设备具有不同的制造商:

$ curl 'http://localhost:9200/zzz/devices/_search?pretty=true&q=*:*'

结果:

{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 93,
"max_score": 1.0,
"hits": [
{
"_index": "zzz",
"_type": "devices",
"_id": "309",
"_score": 1.0,
"_source": {
"title": "Apple iPad Air",
"url": "http://admin.zzz:5000/api/devices/309",
"images": [
{
"url": "http://images.zzz.co.uk/Pb_YD8-Apple-iPad-Air-Space-grey-front.png"
}
],
"model": "iPad Air",
"type": "device",
"id": 309,
"manufacturer": {
"id": 24,
"name": "Apple"
}
}
},
{
"_index": "zzz",
"_type": "devices",
"_id": "330",
"_score": 1.0,
"_source": {
"title": "Apple iPad with Retina Display",
"url": "http://admin.zzz:5000/api/devices/330",
"images": [
{
"url": "http://images.zzz.co.uk/6F_UHO-Apple-iPad-Air-Space-grey-front.png"
}
],
"model": "iPad with Retina Display",
"type": "device",
"id": 330,
"manufacturer": {
"id": 24,
"name": "Apple"
}
}
},
{
"_index": "zzz",
"_type": "devices",
"_id": "1",
"_score": 1.0,
"_source": {
"title": "Apple iPhone 5s",
"url": "http://admin.zzz:5000/api/devices/1",
"images": [
{
"url": "http://images.zzz.co.uk/fEcmFm-Apple-5S-Gold-front.png"
},
{
"url": "http://images.zzz.co.uk/9RDYXY-Apple-5S-Gold-back.png"
}
],
"model": "iPhone 5s",
"type": "device",
"id": 1,
"manufacturer": {
"id": 24,
"name": "Apple"
}
}
},
{
"_index": "zzz",
"_type": "devices",
"_id": "335",
"_score": 1.0,
"_source": {
"title": "Asus Fonepad",
"url": "http://admin.zzz:5000/api/devices/335",
"images": [
{
"url": "http://images.zzz.co.uk/oMOlgt-Asus-Fonepad-black.png"
}
],
"model": "Asus Fonepad",
"type": "device",
"id": 335,
"manufacturer": {
"id": 11,
"name": "Asus Fonepad"
}
}
},
{
"_index": "zzz",
"_type": "devices",
"_id": "328",
"_score": 1.0,
"_source": {
"title": "HTC Desire 610",
"url": "http://admin.zzz:5000/api/devices/328",
"images": [
{
"url": "http://images.zzz.co.uk/QdavNt-HTC-610-Navy.png"
}
],
"model": "Desire 610",
"type": "device",
"id": 328,
"manufacturer": {
"id": 23,
"name": "HTC"
}
}
},
{
"_index": "zzz",
"_type": "devices",
"_id": "347",
"_score": 1.0,
"_source": {
"title": "Huawei E5756",
"url": "http://admin.zzz:5000/api/devices/347",
"images": [
{
"url": "http://images.zzz.co.uk/mJjOiN-Huawei_E5756.png"
}
],
"model": "Huawei E5756",
"type": "device",
"id": 347,
"manufacturer": {
"id": 20,
"name": "Huawei E5756"
}
}
},
{
"_index": "zzz",
"_type": "devices",
"_id": "70",
"_score": 1.0,
"_source": {
"title": "LG G2",
"url": "http://admin.zzz:5000/api/devices/70",
"images": [
{
"url": "http://images.zzz.co.uk/GnTFhn-LG-G2-Black-Front.png"
}
],
"model": "G2",
"type": "device",
"id": 70,
"manufacturer": {
"id": 5,
"name": "LG"
}
}
},
{
"_index": "zzz",
"_type": "devices",
"_id": "342",
"_score": 1.0,
"_source": {
"title": "LG G3",
"url": "http://admin.zzz:5000/api/devices/342",
"images": [
{
"url": "http://images.zzz.co.uk/yH2HFE-Screen_Shot_2014-06-26_at_11.09.40.png"
}
],
"model": "LG G3",
"type": "device",
"id": 342,
"manufacturer": {
"id": 5,
"name": "LG"
}
}
},
{
"_index": "zzz",
"_type": "devices",
"_id": "304",
"_score": 1.0,
"_source": {
"title": "LG Nexus 5",
"url": "http://admin.zzz:5000/api/devices/304",
"images": [
{
"url": "http://images.zzz.co.uk/PxLiur-LG-Nexus5-white-front.png"
}
],
"model": "Nexus 5",
"type": "device",
"id": 304,
"manufacturer": {
"id": 5,
"name": "LG"
}
}
},
{
"_index": "zzz",
"_type": "devices",
"_id": "114",
"_score": 1.0,
"_source": {
"title": "Nokia Lumia 1020",
"url": "http://admin.zzz:5000/api/devices/114",
"images": [
{
"url": "http://images.zzz.co.uk/w0gk6L-Nokia-Lumia1020-yellow-front.png"
}
],
"model": "Lumia 1020",
"type": "device",
"id": 114,
"manufacturer": {
"id": 7,
"name": "Nokia"
}
}
}
]
}
}

如何为 Apple 设备创建别名?我已经尝试过

es.indices.put_alias(index="zzz", name="devices_apple", body={ 
"routing" : "devices_apple",
"filter" : {
"term" : {
"manufacturer.name" : "Apple"
}
}
});

但是http://localhost:9200/cbp/devices/devices_apple什么也没返回。我对 Elasticsearch 很陌生,所以任何提示都值得赞赏。

最佳答案

试试这个:

es.indices.put_alias(index="zzz", name="devices_apple", body="""{ 
"routing" : "devices_apple",
"filter" : {
"term" : {
"manufacturer.name" : "Apple"
}
}
}""")

您可以保存返回值并打印它。如果它有效,它应该包含“{'acknowledged': True}”。

您还可以在此处查看更改:' http://localhost:9200/zzz '。使用“GET _aliases”请求查看索引上是否有任何新别名。

关于python - ElasticSearch - python 别名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25881735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com