2016-12-26 51 views
0

我使用elasticsearch python API在elasticsearch索引上索引JSON对象。弹性搜索汇总字段不起作用..?

我无法通过文档后面的多令牌字段获得预期的结果。

我提供低于我的身体映射代码:

body={"mappings":{ 
     "my_doc": { 
      "properties": { 
       "id": { 
        "properties": { 
         "name": {"type": "string"}, 
         "value": {"type": "keyword"} 
        } 
       }, 
       "name": { 
        "properties": { 
         "first": {"type": "text"}, 
         "last": {"type": "text"} 
        } 
       }, 
       "location": { 
        "properties": { 
         "city": {"type": "text"}, 
         "state": { 
           "type": "text", 
           "fielddata": True, 
           "fields": { 
            "raw": { 
             "type": "string", 
             "index": "not_analyzed" 
            } 
           } 
         }, 
         "street": {"type": "text"}, 
         "postcode": {"type": "text"} 
        } 
       } 
      } 
     } 
    } 
} 

当我使用这个AQG查询:

curl -XGET localhost:9200/my_index/_search -d '{ 
"size": 0, 
"aggs": { 
    "locations": { 
     "terms": { 
      "field": "location.state" 
     } 
    } 
    } 
}' 

我获得令牌,OK 但是,当我使用原始字段:

curl -XGET localhost:9200/my_index/_search -d '{ 
"size": 0, 
"aggs": { 
    "locations": { 
     "terms": { 
      "field": "location.state.raw" 
     } 
    } 
    } 
}' 

我没有获得桶。

有什么建议吗?

最终的映射下松懈的建议是:

body={"mappings":{ 
      "my_doc": { 
       "properties": { 
        "id": { 
         "properties": { 
          "name": {"type": "string"}, 
          "value": {"type": "keyword"} 
         } 
        }, 
        "name": { 
         "properties": { 
          "first": {"type": "text"}, 
          "last": {"type": "text"} 
         } 
        }, 
        "location": { 
         "properties": { 
          "city": {"type": "text"}, 
          "state": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword" 
             } 
            } 
          }, 
          "street": {"type": "text"}, 
          "postcode": {"type": "text"} 
         } 
        } 
       } 
      } 
     } 
    } 

回答

0

在该映射删除

"index": "not_analyzed 

,也将努力

+0

对不起,我继续:{ “错误”:{ “ROOT_CAUSE”: [{“type”:“illegal_argument_exception”,“reason”:“Fielddata在默认情况下禁用了文本字段,在[location.state.raw]中设置fielddata = true,以便通过取消反转索引来加载内存中的fielddata。 ... –

+0

阅读下一个链接https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html将对你非常有用。如果您有任何疑问,请随时询问 – Lax

+0

谢谢松懈!解决了链接。 –