2016-04-13 8 views
1

私のクエリがある感覚を使用しています:私は幹部名「姓」と「FIRSTNAME1さんlastname2」と一致する一致のクエリーを使用しています私はelasticsearchの特定のフィールドのドキュメントの数を数えたいと思います。私は意味で

GET testindexnew1/_search 
{ 
    "fields": ["T","U", "UD", "UE", "gsaentity_executives","extension.viewport","extension.google-site-verification","extension.og:description"], 
    "query": { 
    "bool": { 
     "should": [ 
     { "match": { "gsaentity_executives": "firstname lastname" }}, 
     { "match": { "gsaentity_executives": "firstname2 lastname2" }} 
     ] 
    } 
    }, 
"size": 10, 

    "aggs": { 
    "tags": { 
     "significant_terms": { 
     "field": "newContent" 
     } 
    } 
    }, 

    "highlight" : { 
     "fields" : { 
      "newContent" : {"fragment_size" : 150, "number_of_fragments" : 1} 
     } 
    } 
} 

。また、用語集を使用して文書数を返しています。結果は、私のようなルックスを取得しています:

{ 
    "took": 31, 
    "timed_out": false, 
    "_shards": { 
    "total": 1, 
    "successful": 1, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 6, 
    "max_score": 4.021257, 
    "hits": [ 
     { 
     "_index": "testindexnew1", 
     "_type": "SearchTech", 
     "_id": "http://www.searchtechnologies.com/blog", 
     "_score": 4.021257, 
     "fields": { 
      "U": [ 
      "http://www.searchtechnologies.com/blog" 
      ], 
      "extension.google-site-verification": [ 
      "jP1bIfjuuyZUYfTkYc_O6ZlTHxCm07voTDcMk72Z8oQ" 
      ], 
      "T": [ 
      "Search and Big Data Insights - Search Technologies Blog" 
      ], 
      "UD": [ 
      "http://www.searchtechnologies.com/blog" 
      ], 
      "extension.viewport": [ 
      "width=device-width, initial-scale=1, maximum-scale=1" 
      ], 
      "gsaentity_executives": [ 
      "firstname lastname, firstname2 lastname2" 
      ], 
      "UE": [ 
      "http://www.searchtechnologies.com/blog" 
      ], 
      "extension.og:description": [ 
      "Search Technologies is the largest IT services company dedicated to enterprise search and big data implementation, consulting and managed Services" 
      ] 
     } 
     }, 
     { 
     "_index": "testindexnew1", 
     "_type": "SearchTech", 
     "_id": "http://www.searchtechnologies.com/executive-team", 
     "_score": 2.0106285, 
     "fields": { 
      "U": [ 
      "http://www.searchtechnologies.com/executive-team" 
      ], 
      "extension.google-site-verification": [ 
      "jP1bIfjuuyZUYfTkYc_O6ZlTHxCm07voTDcMk72Z8oQ" 
      ], 
      "T": [ 
      "Search Technologies Executive Team" 
      ], 
      "UD": [ 
      "http://www.searchtechnologies.com/executive-team" 
      ], 
      "extension.viewport": [ 
      "width=device-width, initial-scale=1, maximum-scale=1" 
      ], 
      "gsaentity_executives": [ 
      "firstname lastname, firstname2 lastname2" 
      ], 
      "UE": [ 
      "http://www.searchtechnologies.com/executive-team" 
      ], 
      "extension.og:description": [ 
      "Our executive team is the most experienced in the search and analytics business with an average of more than 18 years experience" 
      ] 
     } 
     }, 
     { 
     "_index": "testindexnew1", 
     "_type": "SearchTech", 
     "_id": "http://www.searchtechnologies.com/solr-hadoop-integration", 
     "_score": 1.3831896, 
     "fields": { 
      "U": [ 
      "http://www.searchtechnologies.com/solr-hadoop-integration" 
      ], 
      "extension.google-site-verification": [ 
      "jP1bIfjuuyZUYfTkYc_O6ZlTHxCm07voTDcMk72Z8oQ" 
      ], 
      "T": [ 
      "Solr | Hadoop Integration" 
      ], 
      "UD": [ 
      "http://www.searchtechnologies.com/solr-hadoop-integration" 
      ], 
      "extension.viewport": [ 
      "width=device-width, initial-scale=1, maximum-scale=1" 
      ], 
      "gsaentity_executives": [ 
      "firstname2 lastname2" 
      ], 
      "UE": [ 
      "http://www.searchtechnologies.com/solr-hadoop-integration" 
      ], 
      "extension.og:description": [ 
      "Solr is the natural choice for searching over Hadoop data. Search Technologies is the leading IT services company dedicated to implementing enterprise search and unstructured big data applications." 
      ] 
     } 
     }, 
     { 
     "_index": "testindexnew1", 
     "_type": "SearchTech", 
     "_id": "http://www.searchtechnologies.com/news-adecco-improves-recruiter-efficiency-with-search", 
     "_score": 1.1300961, 
     "fields": { 
      "U": [ 
      "http://www.searchtechnologies.com/news-adecco-improves-recruiter-efficiency-with-search" 
      ], 
      "extension.google-site-verification": [ 
      "jP1bIfjuuyZUYfTkYc_O6ZlTHxCm07voTDcMk72Z8oQ" 
      ], 
      "T": [ 
      "Search Technologies Helps Adecco Group Significantly Improve Recruiter Efficiency" 
      ], 
      "UD": [ 
      "http://www.searchtechnologies.com/news-adecco-improves-recruiter-efficiency-with-search" 
      ], 
      "extension.viewport": [ 
      "width=device-width, initial-scale=1, maximum-scale=1" 
      ], 
      "gsaentity_executives": [ 
      "firstname lastname" 
      ], 
      "UE": [ 
      "http://www.searchtechnologies.com/news-adecco-improves-recruiter-efficiency-with-search" 
      ], 
      "extension.og:description": [ 
      "Custom Search and Match application based on Cloudera and Solr improves Adecco's recruiters' response times and fill rates." 
      ] 
     } 
     }, 
     { 
     "_index": "testindexnew1", 
     "_type": "SearchTech", 
     "_id": "http://www.searchtechnologies.com/search-big-data-videos", 
     "_score": 1.1300961, 
     "fields": { 
      "U": [ 
      "http://www.searchtechnologies.com/search-big-data-videos" 
      ], 
      "extension.google-site-verification": [ 
      "jP1bIfjuuyZUYfTkYc_O6ZlTHxCm07voTDcMk72Z8oQ" 
      ], 
      "T": [ 
      "Enterprise Search & Big Data Videos" 
      ], 
      "UD": [ 
      "http://www.searchtechnologies.com/search-big-data-videos" 
      ], 
      "extension.viewport": [ 
      "width=device-width, initial-scale=1, maximum-scale=1" 
      ], 
      "gsaentity_executives": [ 
      "firstname lastname" 
      ], 
      "UE": [ 
      "http://www.searchtechnologies.com/search-big-data-videos" 
      ], 
      "extension.og:description": [ 
      "A collection of videos discussing enterprise search and big data concepts, business applications, and real-world case stories." 
      ] 
     } 
     }, 
     { 
     "_index": "testindexnew1", 
     "_type": "SearchTech", 
     "_id": "http://www.searchtechnologies.com/faq", 
     "_score": 1.1300961, 
     "fields": { 
      "U": [ 
      "http://www.searchtechnologies.com/faq" 
      ], 
      "extension.google-site-verification": [ 
      "jP1bIfjuuyZUYfTkYc_O6ZlTHxCm07voTDcMk72Z8oQ" 
      ], 
      "T": [ 
      "Search Technologies: Frequently Asked Questions (FAQ)" 
      ], 
      "UD": [ 
      "http://www.searchtechnologies.com/faq" 
      ], 
      "extension.viewport": [ 
      "width=device-width, initial-scale=1, maximum-scale=1" 
      ], 
      "gsaentity_executives": [ 
      "firstname lastname" 
      ], 
      "UE": [ 
      "http://www.searchtechnologies.com/faq" 
      ], 
      "extension.og:description": [ 
      "Search Technologies FAQ: Where did Search Technologies come from?   What are our key differentiators?  How do our customers view us?" 
      ] 
     } 
     } 
    ] 
    }, 
    "aggregations": { 
    "tags": { 
     "doc_count": 6, 
     "buckets": [ 
     { 
      "key": "lastname", 
      "doc_count": 5, 
      "score": 13.055555555555557, 
      "bg_count": 5 
     }, 
     { 
      "key": "firstname", 
      "doc_count": 5, 
      "score": 13.055555555555557, 
      "bg_count": 5 
     }, 
     { 
      "key": "ceo", 
      "doc_count": 5, 
      "score": 13.055555555555557, 
      "bg_count": 5 
     }, 
     { 
      "key": "lastname2", 
      "doc_count": 3, 
      "score": 7.833333333333333, 
      "bg_count": 3 
     }, 
     { 
      "key": "candidates", 
      "doc_count": 4, 
      "score": 6.7407407407407405, 
      "bg_count": 6 
     }, 
     { 
      "key": "retention", 
      "doc_count": 3, 
      "score": 5.75, 
      "bg_count": 4 
     }, 
     { 
      "key": "firstname2", 
      "doc_count": 3, 
      "score": 5.75, 
      "bg_count": 4 
     }, 
     { 
      "key": "known", 
      "doc_count": 3, 
      "score": 5.75, 
      "bg_count": 4 
     }, 
     { 
      "key": "it’s", 
      "doc_count": 3, 
      "score": 5.75, 
      "bg_count": 4 
     }, 
     { 
      "key": "said", 
      "doc_count": 3, 
      "score": 5.75, 
      "bg_count": 4 
     } 
     ] 
    } 
    } 
} 

あなたは、私が個別に姓、FIRSTNAME1さん、lastname2などのドキュメント数を取得結果から見ることができます。私は私のクエリは全体の幹部のための文書をカウントしたい

"aggregations": { 
    "tags": { 
     "doc_count": 6, 
     "buckets": [ 
     { 
      "key": "lastname", 
      "doc_count": 5, 
      "score": 13.055555555555557, 
      "bg_count": 5 
     }, 
     { 
      "key": "firstname", 
      "doc_count": 5, 
      "score": 13.055555555555557, 
      "bg_count": 5 
     }, 

は、「姓」、「FIRSTNAME1さんlastname2」などに名前を付けるしかし、私は、文書が執行姓と名に分けてカウント取得しています。

私はESを初めて使ったので、おそらく何かを逃したでしょう。ご協力いただきありがとうございます!

答えて

0

あなたは集約されるフィールドに次のようなカスタム・アナライザとのマッピングが必要です。

{ 
    "settings": { 
    "analysis": { 
     "tokenizer": { 
     "comma": { 
      "type": "pattern", 
      "pattern": "," 
     } 
     }, 
     "analyzer": { 
     "comma": { 
      "type": "custom", 
      "tokenizer": "comma", 
      "filter": [ 
      "trim" 
      ] 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "SearchTech": { 
     "properties": { 
     "gsaentity_executives": { 
      "type": "string", 
      "fields": { 
      "comma_separated": { 
       "type": "string", 
       "analyzer": "comma" 
      } 
      } 
     } 

と集計:

"aggs": { 
    "tags": { 
     "terms": { 
     "field": "gsaentity_executives.comma_separated", 
     "size": 10 
     } 
    } 
    } 
+0

それは働いていたが。どうもありがとう。 – Rose

関連する問題