没有消息的putMapping invalid_argument_exception

时间:2019-08-19 21:00:31

标签: node.js elasticsearch

我尝试从elasticsearch javascript客户端调用putMapping,但始终收到状态码为400的错误,invalid_argument_exception。

当我为“文档”索引调用getMapping时,我得到了:

                            <div class="row portfolio-row ignore-thumbnail-settings" data-grid="fitRows" data-posttype-autoplay="true" data-posttype-autoplay-timeout="4000" data-posttype-autoplay-speed="700" data-posttype-autoplay-hover="true" data-posttype-loop="true" data-posttype-pagination="true" data-posttype-navigation="false" data-rtl="false">
                <div id="portfolio-post-4718" class="portfolio-column portfolio-post portfolio-hover-style-1 all wilshire  width1x height1x col-xs-12 col-sm-12 col-md-12" style="">
                        <div class="portfolio-content-container">
                            <div class="portfolio-thumbnail">
                                <img width="920" height="920" src="https://www.pampacasastaging.com/wp-content/uploads/2019/08/920x920-10450-Wilshire-Blvd-UNIT-2A-print-024-024-Bedroom-2-4200x2800-300dpi.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="">                                </div> 
                            <div class="portfolio-caption-content">
                                <a class="portfolio-content-link" href="https://www.pampacasastaging.com/portfolio/wilshire/" target="_self"></a>
                                <div class="portfolio-content-inner">
                                    <div class="portfolio-content-details">
                                        <h5 class="portfolio-title"><a href="https://www.pampacasastaging.com/portfolio/wilshire/" target="_self">wilshire</a></h5>                                        </div>
                                                                        </div>
                            </div>
                        </div>
                                                </div>                        <div class="grid-sizer col-xs-12 col-sm-12 col-md-12"></div>
                                </div>
                        </div>
    </div><!-- #main -->
</div><!-- #primary --> 

我试图用相同的属性调用putMapping并将新参数'index':'not_analyzed'添加到类别字段:

 {
"documents":{
    "mappings": {
         "properties":{
              "category":{"type":"text","fields":{"keyword": 
                         {"type":"keyword","ignore_above":256}}},
              "createdAt":{"type":"text","fields":{"keyword":                                          
                         {"type":"keyword","ignore_above":256}}},
              "id":{"type":"text","fields":{"keyword":                                                                  
                         {"type":"keyword","ignore_above":256}}},
              "info":{"type":"text","fields":{"keyword": 
                         {"type":"keyword","ignore_above":256}}},
              "text":{"type":"text","fields":{"keyword": 
                         {"type":"keyword","ignore_above":256}}},
              "title":{"type":"text","fields":{"keyword": 
                         {"type":"keyword","ignore_above":256}}},
              "visibility":{"type":"boolean"}
            }
    }
}
}

我收到此错误:

esClient.indices.putMapping({
            index: 'documents',
            type: 'document',
            body: {
                document: {
                    properties: {
                        title: { type: 'text' },
                        info: { type: 'text' },
                        text: { type: 'text' },
                        category: { type: 'text', index: 
                           'not_analyzed' 
                        },
                        visibility: { type: 'boolean' },
                        createdAt: { type: 'text' },
                    },
                },
            },
        }, (err, resp) => {
            if (err) {
                console.error(err);
            }
            else {
                console.log('Successfully Created Index', resp);
            }
        });

1 个答案:

答案 0 :(得分:0)

index:'not_analyzed'-我这样做是为了使用“ term”方法来精确查找字符串,但是在Elasticsearch 2.x版本中不推荐使用它(index:“ not_analyzed”)。现在,我只使用field.keyword:'查询字符串'来查找确切的字符串。