我的ES自定义分析器未使用?

时间:2015-05-06 10:14:46

标签: mapping elasticsearch

我正在使用Elasticsearch并使用以下信息创建索引以进行映射和设置。我遇到的问题是我的字段geography.locality应该使用'name_analyser'似乎没有使用它。

{
  "index": "programs",
  "body": {
    "settings": {
      "number_of_shards": 5,
      "analysis": {
        "filter": {
          "elision": {
            "type": "elision",
            "articles": [
              "l",
              "m",
              "t",
              "qu",
              "n",
              "s",
              "j",
              "d"
            ]
          },
          "multi_words": {
            "type": "shingle",
            "min_shingle_size": 2,
            "max_shingle_size": 10
          },
          "name_filter": {
            "type": "edgeNGram",
            "max_gram": 100,
            "min_gram": 2
          }
        },
        "tokenizer": {
          "name_tokenizer": {
            "type": "edgeNGram",
            "max_gram": 100,
            "min_gram": 2
          }
        },
        "analyser": {
          "name_analyser": {          // <-- analyser I want to use on geography.locality
            "tokenizer": "whitespace",
            "type": "custom",
            "filter": [
              "lowercase",
              "multi_words",
              "name_filter",
              "asciifolding"
            ]
          },
          "french": {
            "tokenizer": "letter",
            "filter": [
              "asciifolding",
              "lowercase",
              "elision",
              "stop"
            ]
          },
          "city_name": {
            "type": "custom",
            "tokenizer": "letter",
            "filter": [
              "lowercase",
              "asciifolding"
            ]
          }
        }
      }
    },
    "mappings": {
      "program": {
        "properties": {
          "nid": {
            "type": "integer",
            "index": "not_analyzed"
          },
          "title": {
            "type": "string"
          },
          "language": {
            "type": "string",
            "index": "not_analyzed"
          },
          "regulation": {
            "type": "integer"
          },
          "sales_state": {
            "type": "integer"
          },
          "enabled_dwell": {
            "type": "boolean"
          },
          "enabled_invest": {
            "type": "boolean"
          },
          "delivery_date": {
            "type": "date"
          },
          "address": {
            "properties": {
              "country": {
                "type": "string",
                "index": "not_analyzed"
              },
              "locality": {
                "type": "string",
                "analyser": "name_analyser"
              },
              "postal_code": {
                "type": "integer"
              },
              "thoroughfare": {
                "type": "string",
                "index": "not_analyzed"
              },
              "premise": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "location": {
            "type": "geo_point"
          },
          "geography": {
            "properties": {
              "locality": {
                "type": "string",
                "analyser": "name_analyser"  // ... here :-/
              },
              "department": {
                "type": "string",
                "index": "not_analyzed"
              },
              "region": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "lots": {
            "type": "nested",
            "include_in_all": false,
            "properties": {
              "lot_type": {
                "type": "integer"
              },
              "rooms": {
                "type": "integer"
              },
              "price_vat_inc": {
                "type": "integer"
              },
              "price_reduced_vat_inc": {
                "type": "integer"
              },
              "price_vat_ex": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  }
}

这是ES为该索引注册的映射所给出的输出。

{
  "program": {
    "properties": {
      "address": {
        "properties": {
          "country": {
            "index": "not_analyzed",
            "type": "string"
          },
          "premise": {
            "index": "not_analyzed",
            "type": "string"
          },
          "locality": {
            "type": "string"
          },
          "postal_code": {
            "type": "integer"
          },
          "thoroughfare": {
            "index": "not_analyzed",
            "type": "string"
          }
        }
      },
      "sales_state": {
        "type": "integer"
      },
      "nid": {
        "type": "integer"
      },
      "language": {
        "index": "not_analyzed",
        "type": "string"
      },
      "title": {
        "type": "string"
      },
      "enabled_invest": {
        "type": "boolean"
      },
      "geo_point": {
        "type": "string"
      },
      "lots": {
        "include_in_all": false,
        "type": "nested",
        "properties": {
          "rooms": {
            "include_in_all": false,
            "type": "integer"
          },
          "price_vat_inc": {
            "include_in_all": false,
            "type": "integer"
          },
          "price_vat_ex": {
            "include_in_all": false,
            "type": "integer"
          },
          "lot_type": {
            "include_in_all": false,
            "type": "integer"
          },
          "price_reduced_vat_inc": {
            "include_in_all": false,
            "type": "integer"
          }
        }
      },
      "enabled_dwell": {
        "type": "boolean"
      },
      "delivery_date": {
        "format": "dateOptionalTime",
        "type": "date"
      },
      "regulation": {
        "type": "integer"
      },
      "geography": {
        "properties": {
          "locality": {
            "type": "string"      // name_analyser should show up here right?????
          },
          "department": {
            "index": "not_analyzed",
            "type": "string"
          },
          "region": {
            "index": "not_analyzed",
            "type": "string"
          }
        }
      },
      "location": {
        "type": "geo_point"
      }
    }
  }
}

有人知道我做错了什么吗?我有点迷失了。

2 个答案:

答案 0 :(得分:0)

我猜测索引存在,并且您正尝试使用新的分析器更新设置。实时索引不允许这样做。

提交更新的设置时是否有任何错误?

看一下这个帖子 - Change settings and mappings on existing index in Elasticsearch

http://www.elastic.co/guide/en/elasticsearch/reference/1.x/indices-update-settings.html#update-settings-analysis

答案 1 :(得分:0)

你有一个拼写错误:-),实际上有两个:

    "locality": {
      "type": "string",
      "analyser": "name_analyser"
    },
{p} addressgeography中的

。它应该是analyzer而不是analyser(带有s)。

此外,同样如下:

    "analyser": {
      "name_analyser": {
        "tokenizer": "whitespace",
    ...