How to get the field infomation when _all and _source was set disabled


(Arvin Wong) #1

Hi,
I created an index, which was named test_all, and it has a "table" :
type1. I want to test the usage of "_all" and "_source". Now , I change
their status to false. The mapping as follows:
$ curl -XGET 'localhost:9200/test_all/_mapping/type1?pretty'
{
"test_all" : {
"mappings" : {
"type1" : {
"_all" : {
"enabled" :false
},
"_source" : {
"enabled" : false
},
"properties" : {
"content" : {
"type" : "string",
"analyzer" : "ik"
},
"title" : {
"type" : "string",
"store" : true,
"analyzer" : "ik"
}
}
}
}
}
}

In the table "type1", I store thetitle information. I insert five
document in type1. But, when retrievaling them, I could not find the
field "title" information.

$ curl -XGET 'localhost:9200/test_all/type1/_search?pretty'
{
"took" : 16,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 5,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test_all",
"_type" : "type1",
"_id" : "zWQno3rLS56hkwJ_Y108Dg",
"_score" : 1.0
}, {
"_index" : "test_all",
"_type" : "type1",
"_id" : "BDKa-IP7TDK_iM2VNGFPYw",
"_score" : 1.0
}, {
"_index" : "test_all",
"_type" : "type1",
"_id" : "n97suWSwQACgx35APTOqPg",
"_score" : 1.0
}, {
"_index" : "test_all",
"_type" : "type1",
"_id" : "2P7OblUiQB2Y8ZCtWWWTdg",
"_score" : 1.0
}, {
"_index" : "test_all",
"_type" : "type1",
"_id" : "Lo_PFVeKTEWazwCLbyKAqQ",
"_score" : 1.0
} ]
}
}

Then, I try to resolve it by JAVA API:
public static void indexSearch(Client client){
SearchRequestBuilder searchRequestBuilder=client.prepareSearch("test_all");
searchRequestBuilder.setTypes("type1");
SearchResponse searchResponse=searchRequestBuilder.execute().actionGet();
SearchHit[]hits=searchResponse.getHits().getHits();
System.out.println("count: "+hits.length);
for(SearchHit hit:hits){
System.out.println("----------------------------");
System.out.println("docID: "+hit.getId());
System.out.println("score: "+hit.getScore());
System.out.println("title: "+hit.getFields().get("title").toString());
}
}

and it shows:

Exception in thread "main" count: 5

java.lang.NullPointerException
at es.api.Test_All.indexSearch(Test_All.java:64)
at es.api.Test_All.main(Test_All.java:73)
docID: zWQno3rLS56hkwJ_Y108Dg
score: 1.0

I guess the value doesn't exist.

Can you call me why?

Many Thanks.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/53FAE834.1090000%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


(vineeth mohan-2) #2

Hello Wang ,

By default the _source field stores the input JSON and gives it back for
each document match.
If you disable , ES wont be able to return it.
Hence the result you see.
By default ES wont make any efforts to tap the "Stored" information , it
rather takes the json stored in _source field.

Now to get the text set as "stored" , you need to use the fields option.
Typically , you need to tell ES , you need so and so fields.
This information would be searched in "stored" field space rather than
_source field.

In your query , you need to mention the fields you are interested in -

    searchRequestBuilder.setTypes("type1").fields([ "title" ] )

( equal-ant in Java)

Thanks
Vineeth

On Mon, Aug 25, 2014 at 1:09 PM, Wang Mingxing wmx3ng@gmail.com wrote:

Hi,
I created an index, which was named test_all, and it has a "table" :
type1. I want to test the usage of "_all" and "_source". Now , I change
their status to false. The mapping as follows:
$ curl -XGET 'localhost:9200/test_all/_mapping/type1?pretty'
{
"test_all" : {
"mappings" : {
"type1" : {
"_all" : {
"enabled" : false
},
"_source" : {
"enabled" : false
},
"properties" : {
"content" : {
"type" : "string",
"analyzer" : "ik"
},
"title" : {
"type" : "string",
"store" : true,
"analyzer" : "ik"
}
}
}
}
}
}

In the table "type1", I store the title information. I insert five
document in type1. But, when retrievaling them, I could not find the
field "title" information.

$ curl -XGET 'localhost:9200/test_all/type1/_search?pretty'
{
"took" : 16,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 5,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test_all",
"_type" : "type1",
"_id" : "zWQno3rLS56hkwJ_Y108Dg",
"_score" : 1.0
}, {
"_index" : "test_all",
"_type" : "type1",
"_id" : "BDKa-IP7TDK_iM2VNGFPYw",
"_score" : 1.0
}, {
"_index" : "test_all",
"_type" : "type1",
"_id" : "n97suWSwQACgx35APTOqPg",
"_score" : 1.0
}, {
"_index" : "test_all",
"_type" : "type1",
"_id" : "2P7OblUiQB2Y8ZCtWWWTdg",
"_score" : 1.0
}, {
"_index" : "test_all",
"_type" : "type1",
"_id" : "Lo_PFVeKTEWazwCLbyKAqQ",
"_score" : 1.0
} ]
}
}

Then, I try to resolve it by JAVA API:
public static void indexSearch(Client client){
SearchRequestBuilder
searchRequestBuilder=client.prepareSearch("test_all");
searchRequestBuilder.setTypes("type1");
SearchResponse
searchResponse=searchRequestBuilder.execute().actionGet();
SearchHit[]hits=searchResponse.getHits().getHits();
System.out.println("count: "+hits.length);
for(SearchHit hit:hits){
System.out.println("----------------------------");
System.out.println("docID: "+hit.getId());
System.out.println("score: "+hit.getScore());
System.out.println("title:
"+hit.getFields().get("title").toString());
}
}

and it shows:

Exception in thread "main" count: 5

java.lang.NullPointerException
at es.api.Test_All.indexSearch(Test_All.java:64)
at es.api.Test_All.main(Test_All.java:73)
docID: zWQno3rLS56hkwJ_Y108Dg
score: 1.0

I guess the value doesn't exist.

Can you call me why?

Many Thanks.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/53FAE834.1090000%40gmail.com
https://groups.google.com/d/msgid/elasticsearch/53FAE834.1090000%40gmail.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mD1J2Jx%2B5_%2BppYsd9Uc%3DkAtS%2B9fjTWbJjOYXmAorYP5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(system) #3