在 couchdb 中使用 elasticsearch 在 json 中索引名称
indexing names in json using elasticsearch in couchdb
我正在尝试对我的 json 文档实施 full-text 查询。我想按标题搜索。
我的json如下:
{
"release":{
"genres":{
"genre":"Electronic"
},
"identifiers":{
"identifier":[
{
"description":"A-Side",
"value":"MPO SK 032 A1 G PHRUPMASTERGENERAL T27 LONDON",
"type":"Matrix / Runout"
},
{
"description":"B-Side",
"value":"MPO SK 032 B1",
"type":"Matrix / Runout"
},
{
"description":"C-Side",
"value":"MPO SK 032 C1",
"type":"Matrix / Runout"
},
{
"description":"D-Side",
"value":"MPO SK 032 D1",
"type":"Matrix / Runout"
}
]
},
"status":"Accepted",
"videos":{
"video":[
{
"title":"The Persuader (Jesper Dahlbäck) - Östermalm",
"duration":290,
"description":"The Persuader (Jesper Dahlbäck) - Östermalm",
"src":"http://www.youtube.com/watch?v=AHuQWcylaU4",
"embed":true
},
{
"title":"The Persuader - Vasastaden",
"duration":380,
"description":"The Persuader - Vasastaden",
"src":"http://www.youtube.com/watch?v=5rA8CTKKEP4",
"embed":true
},
{
"title":"The Persuader-Stockholm-Sodermalm",
"duration":335,
"description":"The Persuader-Stockholm-Sodermalm",
"src":"http://www.youtube.com/watch?v=QVdDhOnoR8k",
"embed":true
},
{
"title":"The Persuader - Norrmalm",
"duration":289,
"description":"The Persuader - Norrmalm",
"src":"http://www.youtube.com/watch?v=hy47qgyJeG0",
"embed":true
}
]
},
"labels":{
"label":{
"catno":"SK032",
"name":"Svek"
}
},
"companies":{
"company":[
{
"id":271046,
"catno":"",
"name":"The Globe Studios",
"entity_type_name":"Recorded At",
"resource_url":"http://api.discogs.com/labels/271046",
"entity_type":23
},
{
"id":56025,
"catno":"",
"name":"MPO",
"entity_type_name":"Pressed By",
"resource_url":"http://api.discogs.com/labels/56025",
"entity_type":17
}
]
},
"styles":{
"style":"Deep House"
},
"formats":{
"format":{
"text":"",
"name":"Vinyl",
"qty":2,
"descriptions":{
"description":[
"12\"",
"33 ⅓ RPM"
]
}
}
},
"country":"Sweden",
"id":1,
"released":"1999-03-00",
"artists":{
"artist":{
"id":1,
"anv":"",
"name":"Persuader, The",
"role":"",
"tracks":"",
"join":""
}
},
"title":"Stockholm",
"master_id":5427,
"tracklist":{
"track":[
{
"position":"A",
"duration":"4:45",
"title":"Östermalm"
},
{
"position":"B1",
"duration":"6:11",
"title":"Vasastaden"
},
{
"position":"B2",
"duration":"2:49",
"title":"Kungsholmen"
},
{
"position":"C1",
"duration":"5:38",
"title":"Södermalm"
},
{
"position":"C2",
"duration":"4:52",
"title":"Norrmalm"
},
{
"position":"D",
"duration":"5:16",
"title":"Gamla Stan"
}
]
},
"data_quality":"Complete and Correct",
"extraartists":{
"artist":{
"id":239,
"anv":"",
"name":"Jesper Dahlbäck",
"role":"Music By [All Tracks By]",
"tracks":"",
"join":""
}
},
"notes":"The song titles are the names of Stockholm's districts."
}
}
我已经使用以下命令在 elasticsearch 中为上述文档编制了索引:
curl -X PUT "http://127.0.0.1:9200/_river/smalldiscogs/_meta" -d"
{
""type"": ""couchdb"",
""couchdb"": {
""host"": ""localhost"",
""port"": 5984,
""db"": ""smalldiscogs"",
""filter"": null
},
""index"": {
""index"": ""smalldiscogs"",
""type"": ""smalldiscogs"",
""bulk_size"": ""100"",
""bulk_timeout"": ""10000ms""
}
}"
我的问题是如何只索引标题字段。请帮忙?
由于您使用的是 elasticsearch-river-couchdb 插件,您可以使用 groovy 脚本配置河流,该脚本将删除除您指定的字段之外的所有字段。
插件的 official documentation 中给出了一个示例,简单地相当于将以下 script
添加到 couchdb
对象:
curl -XPUT 'http://127.0.0.1:9200/_river/smalldiscogs/_meta' -d '
{
"type": "couchdb",
"couchdb": {
"host": "localhost",
"port": 5984,
"db": "smalldiscogs",
"filter": null,
"script": "var title = ctx.doc.release.title; ctx.doc.remove("release"); ctx.doc.title = title;"
},
"index": {
"index": "smalldiscogs",
"type": "smalldiscogs",
"bulk_size": "100",
"bulk_timeout": "10000ms"
}
}'
脚本看起来像这样,它将简单地从文档中删除除 title
之外的所有字段:
var title = ctx.doc.release.title; <--- remember the title
ctx.doc.remove("release"); <--- remove all fields
ctx.doc.title = title; <--- re-add only the title field
我正在尝试对我的 json 文档实施 full-text 查询。我想按标题搜索。
我的json如下:
{
"release":{
"genres":{
"genre":"Electronic"
},
"identifiers":{
"identifier":[
{
"description":"A-Side",
"value":"MPO SK 032 A1 G PHRUPMASTERGENERAL T27 LONDON",
"type":"Matrix / Runout"
},
{
"description":"B-Side",
"value":"MPO SK 032 B1",
"type":"Matrix / Runout"
},
{
"description":"C-Side",
"value":"MPO SK 032 C1",
"type":"Matrix / Runout"
},
{
"description":"D-Side",
"value":"MPO SK 032 D1",
"type":"Matrix / Runout"
}
]
},
"status":"Accepted",
"videos":{
"video":[
{
"title":"The Persuader (Jesper Dahlbäck) - Östermalm",
"duration":290,
"description":"The Persuader (Jesper Dahlbäck) - Östermalm",
"src":"http://www.youtube.com/watch?v=AHuQWcylaU4",
"embed":true
},
{
"title":"The Persuader - Vasastaden",
"duration":380,
"description":"The Persuader - Vasastaden",
"src":"http://www.youtube.com/watch?v=5rA8CTKKEP4",
"embed":true
},
{
"title":"The Persuader-Stockholm-Sodermalm",
"duration":335,
"description":"The Persuader-Stockholm-Sodermalm",
"src":"http://www.youtube.com/watch?v=QVdDhOnoR8k",
"embed":true
},
{
"title":"The Persuader - Norrmalm",
"duration":289,
"description":"The Persuader - Norrmalm",
"src":"http://www.youtube.com/watch?v=hy47qgyJeG0",
"embed":true
}
]
},
"labels":{
"label":{
"catno":"SK032",
"name":"Svek"
}
},
"companies":{
"company":[
{
"id":271046,
"catno":"",
"name":"The Globe Studios",
"entity_type_name":"Recorded At",
"resource_url":"http://api.discogs.com/labels/271046",
"entity_type":23
},
{
"id":56025,
"catno":"",
"name":"MPO",
"entity_type_name":"Pressed By",
"resource_url":"http://api.discogs.com/labels/56025",
"entity_type":17
}
]
},
"styles":{
"style":"Deep House"
},
"formats":{
"format":{
"text":"",
"name":"Vinyl",
"qty":2,
"descriptions":{
"description":[
"12\"",
"33 ⅓ RPM"
]
}
}
},
"country":"Sweden",
"id":1,
"released":"1999-03-00",
"artists":{
"artist":{
"id":1,
"anv":"",
"name":"Persuader, The",
"role":"",
"tracks":"",
"join":""
}
},
"title":"Stockholm",
"master_id":5427,
"tracklist":{
"track":[
{
"position":"A",
"duration":"4:45",
"title":"Östermalm"
},
{
"position":"B1",
"duration":"6:11",
"title":"Vasastaden"
},
{
"position":"B2",
"duration":"2:49",
"title":"Kungsholmen"
},
{
"position":"C1",
"duration":"5:38",
"title":"Södermalm"
},
{
"position":"C2",
"duration":"4:52",
"title":"Norrmalm"
},
{
"position":"D",
"duration":"5:16",
"title":"Gamla Stan"
}
]
},
"data_quality":"Complete and Correct",
"extraartists":{
"artist":{
"id":239,
"anv":"",
"name":"Jesper Dahlbäck",
"role":"Music By [All Tracks By]",
"tracks":"",
"join":""
}
},
"notes":"The song titles are the names of Stockholm's districts."
}
}
我已经使用以下命令在 elasticsearch 中为上述文档编制了索引:
curl -X PUT "http://127.0.0.1:9200/_river/smalldiscogs/_meta" -d"
{
""type"": ""couchdb"",
""couchdb"": {
""host"": ""localhost"",
""port"": 5984,
""db"": ""smalldiscogs"",
""filter"": null
},
""index"": {
""index"": ""smalldiscogs"",
""type"": ""smalldiscogs"",
""bulk_size"": ""100"",
""bulk_timeout"": ""10000ms""
}
}"
我的问题是如何只索引标题字段。请帮忙?
由于您使用的是 elasticsearch-river-couchdb 插件,您可以使用 groovy 脚本配置河流,该脚本将删除除您指定的字段之外的所有字段。
插件的 official documentation 中给出了一个示例,简单地相当于将以下 script
添加到 couchdb
对象:
curl -XPUT 'http://127.0.0.1:9200/_river/smalldiscogs/_meta' -d '
{
"type": "couchdb",
"couchdb": {
"host": "localhost",
"port": 5984,
"db": "smalldiscogs",
"filter": null,
"script": "var title = ctx.doc.release.title; ctx.doc.remove("release"); ctx.doc.title = title;"
},
"index": {
"index": "smalldiscogs",
"type": "smalldiscogs",
"bulk_size": "100",
"bulk_timeout": "10000ms"
}
}'
脚本看起来像这样,它将简单地从文档中删除除 title
之外的所有字段:
var title = ctx.doc.release.title; <--- remember the title
ctx.doc.remove("release"); <--- remove all fields
ctx.doc.title = title; <--- re-add only the title field