• 请不要在回答技术问题时复制粘贴 AI 生成的内容
kisshere
V2EX  ›  程序员

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

  •  
  •   kisshere · Apr 22, 2019 · 1683 views
    This topic created in 2682 days ago, the information mentioned may be changed or developed.

    现在有一批标签,每个标签的名称对应其标签 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  
       Apr 23, 2019
    可以
    mapping 的时候用
    "type": "nested"

    query 的时候用
    "match": {
    "image_tags.image_tag_name": "sleeping, grass"
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5783 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 03:32 · PVG 11:32 · LAX 20:32 · JFK 23:32
    ♥ Do have faith in what you're doing.