elasticsearch,categories,Arrays,elasticsearch,Categories" /> elasticsearch,categories,Arrays,elasticsearch,Categories" />

Arrays 处理elasticsearch文档中的类别

Arrays 处理elasticsearch文档中的类别,arrays,elasticsearch,categories,Arrays,elasticsearch,Categories,我一直在努力解决这个问题,需要一些帮助 我有一个PHP文档数组,看起来像这样 array("title"=>"some title", "description" => "Short description", "categories" => array ( array("id" => "1", "name" => "category 1"), array("id" =>

我一直在努力解决这个问题,需要一些帮助

我有一个PHP文档数组,看起来像这样

array("title"=>"some title",  
      "description" => "Short description",
      "categories" => array ( array("id" => "1", "name" => "category 1"),
                              array("id" => "5", "name" => "category 5"),
                              array("id" => "55", "name" => "category 55"),
                             )
);
所以基本上我有一个文档,它有很多类别。我的最终目标是按ID返回包含特定类别的所有文档

我有设置映射,文档索引正常。我尝试了category的嵌套映射类型(完全并没有映射)和List类型,但在创建映射时出现错误,这两种类型都不起作用

我如何设置列表的示例

array(
    '_source' => array(
        'enabled' => true
    ),
    'properties' => array(                    
        'title' => array(
            'type' => 'string',
            'analyzer' => 'standard'
        ),            
        'description' => array(
            'type' => 'string',
            'analyzer' => 'standard'
        ),            
        'categories' => array(
            "type" => "lists",
            "properties"=> array(
                    "id" => array("type"=> "integer" ),
                    "name" => array( "type"=> "string" ),
                ),
        ),

    )
    );
为了完整性,我如何将其设置为嵌套的

array(
    '_source' => array(
        'enabled' => true
    ),
    'properties' => array(                    
        'title' => array(
            'type' => 'string',
            'analyzer' => 'standard'
        ),            
        'description' => array(
            'type' => 'string',
            'analyzer' => 'standard'
        ),            
        'categories' => array(
            "type" => "nested",
            "properties"=> array(
                    "id" => array("type"=> "integer" ),
                    "name" => array( "type"=> "string" ),
                ),
        ),

    )
    );
当尝试对嵌套映射进行搜索时,它告诉我

 QueryParsingException:  [nested] nested object under path [categories] is not of nested type
当尝试对默认为系统查找的未映射类别集进行嵌套搜索时,它也会返回与上述相同的错误

我的问题是:

我应该为这些类别数组设置什么映射

给定一个match_all查询,我应该使用什么过滤器以及如何获取单个类别


提前非常感谢所有花时间阅读本文的人,更不用说回答了。我真的希望你能帮忙

答案很简单。我误读了文档,在映射请求中添加了一个不需要的额外对象类型

        'categories' => array(
        "type" => "lists",
        "properties"=> array(
                "id" => array("type"=> "integer" ),
                "name" => array( "type"=> "string" ),
            ),
    ),
应该是

        'categories' => array(          
        "properties"=> array(
                "id" => array("type"=> "integer" ),
                "name" => array( "type"=> "string" ),
            ),
    ),
数组类型不需要定义为类型,它假定为数组。一旦删除,它将正确加载映射


现在开始搜索

考虑到嵌套的错误,我建议从方程中取出PHP,使用curl或Marvel的Sense接口直接在ES中进行映射,并在那里执行测试查询。在您确定了哪个映射和哪个查询可以工作之后,尝试用PHP翻译所有内容。我将试一试。到目前为止,我一直在使用官方的API,因此如果还必须使用curl/json,那将是一件很遗憾的事情。但如果这能让它工作起来,那么这就是我需要的钥匙。@Andreestefan再次感谢你的建议。这是正确的选择。在每次查看日志的过程中,我都对它进行了调试,是的,删除了所有人为错误。祝你一切顺利,谢谢。:-酷。别担心。