Elasticsearch Nest with Logstash 神奇故障一则 ”返回了搜索结果,但所有字段都是null“

这与 Nest 默认的字段名映射规则有关。C# 项目字段名往往是 CamelCase,然而 Nest API在创建索引时,默认会将 CamelCase 的字段名,转换为 camelCase 的字段名。当然,查询的时候,它也会精确的按照 camelCase 字段名映射数据。如果你只用 Nest,其实是不会有任何问题的。毕竟 AutoMapper 对字段名大小写是很宽容的。

当我们引入 Logstash 动态更新索引之后,不和谐的一幕出现了。凡是 Logstash 更新的过数据,查询的时候会返回搜索结果,但所有字段的值都是null。这是因为Logstash在更新索引的时候,没有做 CamelCase => camelCase 的字段名转换。


        public static void AddElasticsearch(
            this IServiceCollection services, string connectionUrl, string connectionIndex)
            var defaultIndex = connectionIndex;

            var settings = new ConnectionSettings(new Uri(connectionUrl))
            settings.DefaultFieldNameInferrer(p => p);
            var client = new ElasticClient(settings);


需要注意的是,代码修改后,别忘记重建索引。否则你会发现原来不正常的( Logstash更新过的数据)都正常了,原来搜索正常的,现在却所有字段名都变成了null。

Tips collection

  • Buefy is a lightweight UI components library for Vue.js based on Bulma
  • @keyup.enter="eventHandler" doesn't work in el-input, but @keyup.enter.native="eventHandler" does. #element-ui
  • git rm -rf . && git clean -fxd is the best way to delete all files except .git directory. #git
  • To make your dynamic LINQ query safe, you must use placeholders for all user input. Never concatenate your string! #dotnetcore
  • try_files $uri $uir/ =404; is better than try_files $uri $uri/ /index.html;, because it can avoid endless loop when /index.html doesn't exist. #nginx
  • git tag -n99 show tags along with annotations Reference
  • new crontab task added
    0 6 * * * /bin/docker container prune -f 
    10 6 * * * /bin/docker rmi $(/bin/docker images -f "dangling=true" -q)

an idea for Pak'n Save users to save fuel cost

PknSave fuel voucher is often wasted by their members because their tank is full before it expires automatically. So the idea is, we can share the fuel vouchers through a mobile app.

  1. If it is big enough, you print a voucher whatever you need or not.
  2. If you don't need to fuel your car, post this voucher on our app and set the amount with expire time.
  3. If you need fuel for your car but have not a voucher, open the app and try to find an unused one. When you decide to use it, you booked it so other people cannot use it anymore. If you eventually didn't use it, put it back into the voucher pool.

Sounds great? Let's do it. If you want to contribute to this side project, contact me with [email protected]

Seafile server configuration on CentOS 8

I am using the docker-compose version. The first problem I met was none of Seafile's concerns, it is actually a bug of docker. All of the containers cannot reach the internet (cannot resolve any DNS). The solution is at here.

After fixed the issue above, the Seafile server runs well on centos. However, there are still two issues that need to be addressed.

The first one is about the head icon of a user. It simply cannot display. You can easily found that the host part of the head icon is wrong. You need to edit "shared/seafile/conf/ccnet.conf" and change the SERVICE_URL to your real hostname in the [General] section.

The second one is similar, if you don't fix it, you cannot download any of the file you uploaded. This time, you need to edit "shared/seafile/conf/seahub_settings.py" and change the last line to "https://your.domain.name/seafhttp".

tmux super simple guide

echo 'set -g mouse on' >> ~/.tmux.conf
tmux new -s tmux3
^b %
^b "
^b d
tmux attach -t tmux3