Elasticsearch嵌套匹配上一个值

2024-06-26 03:33:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我们有第&;条;将作者编辑为数组。需要检查有多少文章最后编辑的特定作者

数据:

{
    "Article" : [
      {
        "id" : 12
        "title" : "An article title",
        "categories" : [1,3,5,7],
        "tag" : ["elasticsearch", "symfony",'Obtao'],
        "author" : [
            {
                "firstname" : "Francois",
                "surname": "francoisg",
                "id" : 18
            },
            {
                "firstname" : "Gregory",
                "surname" : "gregquat"
                "id" : "2"
            }
        ]
      }
    },
    {
        "id" : 13
        "title" : "A second article title",
        "categories" : [1,7],
        "tag" : ["elasticsearch", "symfony",'Obtao'],
        "author" : [
            {
                "firstname" : "Gregory",
                "surname" : "gregquat",
                "id" : "2"
            },
            {
                "firstname" : "Francois",
                "surname": "francoisg",
                "id" : 18
            }
        ]
      }
}

请求数据: 网址:http://localhost:9200/book/articles/_count/

For example `Gregory` & `Francois` should get one article as count.

请让我知道如何只比较第一个对象&;获取结果


Tags: 数据id编辑titletagarticle作者surname
1条回答
网友
1楼 · 发布于 2024-06-26 03:33:48

我们不能直接过滤,但是可以通过在上次编辑的author中添加额外的属性来解决这个问题

{
    "Article" : [
      {
        "id" : 12
        "title" : "An article title",
        "categories" : [1,3,5,7],
        "tag" : ["elasticsearch", "symfony",'Obtao'],
        "author" : [
            {
                "firstname" : "Francois",
                "surname": "francoisg",
                "id" : 18,
                "is_last_edited_staff": true
            },
            {
                "firstname" : "Gregory",
                "surname" : "gregquat"
                "id" : "2",
                "is_last_edited_staff": false
            }
        ]
      }
    },
    {
        "id" : 13
        "title" : "A second article title",
        "categories" : [1,7],
        "tag" : ["elasticsearch", "symfony",'Obtao'],
        "author" : [
            {
                "firstname" : "Gregory",
                "surname" : "gregquat",
                "id" : "2",
                "is_last_edited_staff": true
            },
            {
                "firstname" : "Francois",
                "surname": "francoisg",
                "id" : 18,
                "is_last_edited_staff": false
            }
        ]
      }
}

相关问题 更多 >