2014-01-08 85 views
1

我在弹性搜索的索引中有以下映射。没有结果elasticsearch查询multi_field时

{ 
"mail": { 
    "properties": { 
     "project": { 
      "type": "string", 
      "index": "not_analyzed", 
      "null_value": "na", 
      "include_in_all": "false" 
     }, 
     "mailbox": { 
      "type": "string", 
      "index": "not_analyzed", 
      "null_value": "#na", 
      "store" : "yes" 
     }, 
     "path": { 
      "type": "string", 
      "index": "not_analyzed", 
      "null_value": "#na", 
      "store" : "yes" 
     }, 
     "messageid": { 
      "type": "string", 
      "index": "not_analyzed", 
      "null_value": "na", 
      "include_in_all": "false" 
     }, 
     "nodeid": 
     { 
      "type": "string", 
      "index": "not_analyzed", 
      "null_value": "na", 
      "include_in_all": "false", 
      "store" : "yes" 
     }, 
     "replyto": { 
      "type": "string", 
      "index": "not_analyzed", 
      "null_value": "na", 
      "include_in_all": "false" 
     }, 
     "references": { 
      "type": "string", 
      "index": "not_analyzed", 
      "null_value": "na", 
      "include_in_all": "false" 
     }, 
     "subject": { 
      "boost": "3.0", 
      "type": "string", 
      "term_vector": "with_positions_offsets", 
      "analyzer": "snowball" 
     }, 
     "from": { 
      "type": "nested", 
      "properties": { 
       "name": { 
        "type" : "multi_field", 
        "fields" : { 
         "name" : {"type" : "string", "analyzer" : "standard", "index" : "analyzed"}, 
         "untouched" : {"type" : "string", "index" : "not_analyzed"} 
        } 
       }, 
       "address": { 
        "type": "string", 
        "analyzer": "analyzer_email" 
       }, 
       "nodeid": { 
        "type": "string", 
        "index": "not_analyzed", 
        "store" : "yes" 
       }, 
       "facet": { 
        "type": "string", 
        "index": "not_analyzed", 
        "store" : "yes" 
       } 
      } 
     }, 
     "to": { 
      "type": "nested", 
      "properties":{ 
       "name": { 
        "type": "string", 
        "analyzer":"analyzer_keyword" 
       }, 
       "address": { 
        "type": "string", 
        "analyzer": "analyzer_email" 
       }, 
       "nodeid": { 
        "type": "string", 
        "index": "not_analyzed", 
        "store" : "yes" 
       }, 
       "facet": { 
        "type": "string", 
        "index": "not_analyzed", 
        "store" : "yes" 
       } 
      } 
     }, 
     "cc": { 
      "type": "nested", 
      "properties":{ 
       "name": { 
        "type": "string", 
        "analyzer":"analyzer_keyword" 
       }, 
       "address": { 
        "type": "string", 
        "analyzer": "analyzer_email" 
       }, 
       "nodeid": { 
        "type": "string", 
        "index": "not_analyzed", 
        "store" : "yes" 
       }, 
       "facet": { 
        "type": "string", 
        "index": "not_analyzed", 
        "store" : "yes" 
       } 
      } 
     }, 
     "bcc": { 
      "type": "nested", 
      "properties":{ 
       "name": { 
        "type": "string", 
        "analyzer":"analyzer_keyword" 
       }, 
       "address": { 
        "type": "string", 
        "analyzer": "analyzer_email" 
       }, 
       "nodeid": { 
        "type": "string", 
        "index": "not_analyzed", 
        "store" : "yes" 
       }, 
       "facet": { 
        "type": "string", 
        "index": "not_analyzed", 
        "store" : "yes" 
       } 
      } 
     }, 
     "message_snippet": { 
      "type": "string", 
      "index": "no", 
      "include_in_all": "false" 
     }, 
     "text_messages": { 
      "type": "string", 
      "store": "yes", 
      "term_vector": "with_positions_offsets", 
      "analyzer": "snowball" 
     }, 
     "html_messages": { 
      "type": "string", 
      "store": "yes", 
      "term_vector": "with_positions_offsets", 
      "analyzer": "snowball" 
     }, 
     "message_attachments": { 
      "dynamic": "true", 
      "properties":{ 
       "filename":{ 
        "type": "string", 
        "store": "yes" 
       }, 
       "content":{ 
        "type": "string", 
        "store": "yes", 
        "term_vector": "with_positions_offsets", 
        "analyzer": "snowball" 
       }, 
       "hash":{ 
        "type": "string", 
        "store": "yes", 
        "analyzer": "analyzer_keyword" 
       }, 
       "nodeid":{ 
        "type": "string" 
       } 
      } 
     }, 
     "date": { 
      "type": "date" 
     }, 
     "entities": { 
      "type": "nested", 
      "properties": { 
       "name": { 
        "type": "string", 
        "analyzer": "analyzer_keyword" 
       }, 
       "type": { 
        "type": "string", 
        "analyzer": "analyzer_keyword" 
       }, 
       "nodeid":{ 
        "type": "string" 
       }, 
       "facet": { 
        "type": "string", 
        "index": "not_analyzed", 
        "store" : "yes" 
       } 
      } 
     } 
    } 
} 
} 

我尝试使用以下查询搜索mail.from.name字段,但是我没有给出任何结果。

{ 
"query": { 
"nested": { 
    "path": "from", 
    "query": { 
    "term": { 
     "name": "mark" 
    } 
    } 
} 
} 
} 

我的映射或查询有什么问题?

样本文件看起来像这样

{ 
    "project": "test", 
    "mailbox": "test.pst", 
    "messageid": "5e667f7f-4421-4836-91f3-8b5216c04839", 
    "nodeid": "671", 
    "subject": "No Subject", 
    "from": [ 
    { 
     "name": "Mike Johnson", 
     "address": "[email protected]", 
     "nodeid": "3", 
     "facet": "Mike Johnson" 
    } 
    ], 
    "to": [ 
    { 
     "name": "John Doe", 
     "address": "[email protected]", 
     "nodeid": "367", 
     "facet": "John Doe" 
    } 
    ], 
    "cc": [], 
    "bcc": [], 
    "textbody": "this is a test email with no further lines of text", 
    "htmlbody": "", 
    "snippet": "", 
    "transmitted": "", 
    "replyto": "", 
    "references": "", 
    "attachments": [], 
    "entities": [ 
    { 
     "name": "google", 
     "type": "organization", 
     "nodeid": "656", 
     "facet": "google" 
    } 
    ], 
    "domains": [ 
    "google.com" 
    ], 
    "path": "" 
} 

回答

1

您需要在您再次查询解决nested objects

{ 
    "query": { 
     "nested": { 
      "path": "from", 
      "query": { 
       "term": { 
        "from.name": "mike" 
       } 
      } 
     } 
    } 
} 
+0

TNX奏效! – Martijn