Created
April 29, 2011 07:23
-
-
Save jfiedler/947984 to your computer and use it in GitHub Desktop.
Curl / Java API Recreation of Elastic Search 0.16.0 Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package itembedded.search.search; | |
import static org.elasticsearch.index.query.xcontent.QueryBuilders.termQuery; | |
import junit.framework.Assert; | |
import org.elasticsearch.action.search.SearchResponse; | |
import org.elasticsearch.client.Client; | |
import org.elasticsearch.client.transport.TransportClient; | |
import org.elasticsearch.common.transport.InetSocketTransportAddress; | |
import org.elasticsearch.search.SearchHits; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class ES16ReproductionTest | |
{ | |
private Client client; | |
@Before | |
public void before() | |
{ | |
client = new TransportClient().addTransportAddress( new InetSocketTransportAddress( "localhost", 9300 ) ); | |
} | |
@After | |
public void after() | |
{ | |
client.close(); | |
} | |
@Test | |
public void test() | |
{ | |
SearchResponse r = | |
client.prepareSearch( "test" ).setTypes( "test_record_main" ) | |
.setQuery( termQuery( "doc.payload.test_record_main.string_not_analyzed__s", "foo" ) ).execute() | |
.actionGet(); | |
SearchHits hits = r.getHits(); | |
Assert.assertEquals( "Unexpected number of hits", 1, hits.getTotalHits() ); | |
Assert.assertEquals( "Unexpected hit", "d1", hits.getAt( 0 ).getId() ); | |
r = | |
client.prepareSearch( "test" ).setTypes( "test_record_main" ) | |
.setQuery( termQuery( "doc.payload.test_record_main.string_not_analyzed2__s", "bar" ) ).execute() | |
.actionGet(); | |
hits = r.getHits(); | |
Assert.assertEquals( "Unexpected number of hits", 1, hits.getTotalHits() ); | |
Assert.assertEquals( "Unexpected hit", "d1", hits.getAt( 0 ).getId() ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT 'http://localhost:9200/test/' | |
curl -XPUT 'http://localhost:9200/test/test_record_main/_mapping' -d ' | |
{ | |
"test_record_main":{ | |
"dynamic":false, | |
"_source":{ | |
"store":"yes", | |
"compress":true | |
}, | |
"dynamic_templates":[ | |
{ | |
"string__s":{ | |
"match":"*__s", | |
"mapping":{ | |
"type":"multi_field", | |
"fields":{ | |
"{name}":{"type":"string","index":"not_analyzed"}, | |
"text":{"type":"string","index":"analyzed"} | |
} | |
} | |
} | |
} | |
], | |
"properties":{ | |
"doc":{ | |
"type":"object", | |
"dynamic":"false", | |
"properties":{ | |
"payload":{"type":"object","dynamic":"true"} | |
} | |
} | |
} | |
} | |
} | |
' | |
curl -XPUT 'http://localhost:9200/test/test_record_main/d1' -d ' | |
{ | |
"doc":{ | |
"payload":{ | |
"test_record_main":{ | |
"string_not_analyzed__s":"foo", | |
"string_not_analyzed2__s":"bar" | |
} | |
} | |
} | |
} | |
' | |
curl -XPUT 'http://localhost:9200/test/test_record_main/d2' -d ' | |
{ | |
"doc":{ | |
"payload":{ | |
"test_record_main":{ | |
"string_not_analyzed__s":"bar", | |
"string_not_analyzed2__s":"foo" | |
} | |
} | |
} | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment