2017-07-06 151 views
0

我们有文章&作为数组编辑的作者。需要检查特定作者最后编辑的文章数量。Elasticsearch嵌套匹配最后的值

数据:

{ 
    "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. 

请让我知道如何比较第一对象只&得到结果。

回答

0

我们不能直接过滤,但可以通过在上次编辑的作者中添加额外属性来解决此问题。

{ 
    "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 
      } 
     ] 
     } 
}