为什么在Elasticsearch中创建索引时这个新映射没有生效?

时间:2015-04-03 10:35:02

标签: elasticsearch mapping

我正在使用elasticsearch 1.5.0。

我按照以下方式创建一个新索引并将一些推文下载到新索引中OK,但是当我查看实际映射时它没有使用此映射,但似乎试图找出映射本身。我在这里做错了什么?

curl -XPUT 'http://localhost:9200/tweets' -d '
{
  "tweets" : {
    "mappings" : {
      "tweet" : {
      "properties" : {
          "created_at" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss"
          },
          "day" : {
            "type" : "integer"
          },
          "favorite_count" : {
            "type" : "integer"
          },
          "hashtags" : {
            "properties" : {
              "indices" : {
              "type" : "integer"
          },
          "text" : {
            "type" : "string",
            "index" : "analyzed",
            "analyzer" : "standard"
          }
        }
      },
        "id_str" : {
          "type" : "long"
        },
        "in_reply_to_screen_name" : {
          "type" : "string",
          "index" : "not_analyzed"
        },
        "month" : {
          "type" : "integer"
        },
        "screen_name" : {
          "type" : "string",
          "index" : "not_analyzed"
        },
        "text" : {
          "type" : "string",
          "index" : "analyzed",
          "analyzer" : "standard"
        },
        "urls" : {
          "properties" : {
            "display_url" : {
              "type" : "string"
            },
            "expanded_url" : {
              "type" : "string",
              "index" : "not_analyzed"
            },
            "indices" : {
              "type" : "long"
            },
            "url" : {
              "type" : "string",
              "index" : "not_analyzed"
            }
          }
        },
        "user_mentions" : {
          "properties" : {
            "id" : {
              "type" : "long"
            },
            "id_str" : {
              "type" : "long"
            },
            "indices" : {
              "type" : "long"
            },
            "name" : {
              "type" : "string",
              "index" : "not_analyzed"
            },
            "screen_name" : {
              "type" : "string",
              "index" : "not_analayzed"
            }
          }
        },
        "year" : {
          "type" : "integer"
        }
       }
      }
    }
  }
}'

当我测试将一些推文下载到索引中并检查我得到的映射时:

curl -XGET 'localhost:9200/tweets/_mapping/tweet?pretty'

{
"tweets" : {
  "mappings" : {
    "tweet" : {
      "properties" : {
        "created_at" : {
          "type" : "string"
        },
        "day" : {
          "type" : "string"
        },
        "favorite_count" : {
          "type" : "long"
        },
        "hashtags" : {
          "properties" : {
            "indices" : {
              "type" : "long"
            },
            "text" : {
              "type" : "string"
            }
          }
        },
        "id_str" : {
          "type" : "string"
        },
        "in_reply_to_screen_name" : {
          "type" : "string"
        },
        "month" : {
          "type" : "string"
        },
        "screen_name" : {
          "type" : "string"
        },
        "text" : {
          "type" : "string"
        },
        "urls" : {
          "properties" : {
            "display_url" : {
              "type" : "string"
            },
            "expanded_url" : {
              "type" : "string"
            },
            "indices" : {
              "type" : "long"
            },
            "url" : {
              "type" : "string"
            }
          }
        },
        "user_mentions" : {
          "properties" : {
            "id" : {
              "type" : "long"
            },
            "id_str" : {
              "type" : "string"
            },
            "indices" : {
              "type" : "long"
            },
            "name" : {
              "type" : "string"
            },
            "screen_name" : {
              "type" : "string"
            }
          }
        },
        "year" : {
          "type" : "string"
        }
      }
    }
  }
}
}

当我检查索引推文的映射时,我得到以下结果,然后我将任何推文编入索引:

curl -XGET 'localhost:9200/tweets/_mapping?pretty'
{
  "tweets" : {
    "mappings" : { }
  }
}

1 个答案:

答案 0 :(得分:0)

你是否注意到从试图创建索引的帖子中返回的错误?在" screen_name"你有" not_analayzed"。将其改为" not_analyzed"你会没事的。