简体   繁体   中英

Elasticsearch how search in multiple fields

I am using elasticsearch 1.2.1 and I want to do a search from javascript with several fields , for instance, by title and content.

My code is:

 var data = { q: 'title: test};         
 $.ajax({
     data:  data,
     url: http://localhost:9200/_search,
     type:  'GET',
     success: function (data) {
         $.each(data.hits.hits, function(position,hit) {
            $("#<portlet:namespace/>search-pattern").append( '<li>' + hit._source.title + '</li>' );
         });
     }
 });

But in addition to search for a title also want to look for the content field .

What should be the value for the attribute data in order to search not only by the field 'title' but also by the field 'content'?

Someone can help me?

Thanks in advance

尝试使用请求正文搜索 ,使用查询DSL指定条件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM