V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
kisshere
V2EX  ›  程序员

elasticsearch 中,能否以数组的形式存储并只搜索数组特定的值?

  •  
  •   kisshere · 2019-04-22 13:34:20 +08:00 · 1256 次点击
    这是一个创建于 1831 天前的主题,其中的信息可能已经有所发展或是发生改变。

    现在有一批标签,每个标签的名称对应其标签 id,如下所示:

    <?php
    $image_tags=
    [
        [
        	'image_tag_id'=>1513,
            'image_tag_name'=>'red flower'
        ],
        [
        	'image_tag_id'=>534,
            'image_tag_name'=>'brown cat'
        ],
        [
        	'image_tag_id'=>9677,
            'image_tag_name'=>'grass'
        ],
        [
        	'image_tag_id'=>32,
            'image_tag_name'=>'sleeping'
        ]
    ]
    ?>
    
    

    现在我该在 elasticsearch 中以哪种 datatype 的形式存储该$image_tags,可以让我在查询“ image_tag_name ”的时候,提取出对应的“ image_tag_id ”,即只索引“ image_tag_name ”而不索引“ image_tag_id ”?

    MintZX
        1
    MintZX  
       2019-04-23 02:40:19 +08:00
    可以
    mapping 的时候用
    "type": "nested"

    query 的时候用
    "match": {
    "image_tags.image_tag_name": "sleeping, grass"
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2854 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:38 · PVG 20:38 · LAX 05:38 · JFK 08:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.